zoukankan      html  css  js  c++  java
  • [Ubuntu] 如何设置静态 IP 和 DNS

    编辑 /etc/network/interfaces 来设置 IP 和 DNS 解析服务器: 

    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 192.168.1.6
            gateway 192.168.1.1
            netmask 255.255.255.0
            dns-nameservers 192.168.1.1
            #network 192.168.1.0
            #broadcast 192.168.1.255

    多个 DNS 解析服务器之间使用空格分隔:

    dns-nameservers 192.168.1.1 8.8.8.8

    使修改立即生效:

    sudo ifdown eth0 && sudo ifup eth0

    若未能即时生效,可尝试将 /etc/resolv.conf 设置为 /run/resolvconf/resolv.conf 的软连接:

    ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

    如果只是临时更改 DNS 服务器,编辑 /etc/resolv.conf,添加以下内容:

    nameserver 8.8.8.8 

    resolv.conf 是个动态文件,每次开机会被重新覆盖,因此要添加永久性DNS,采用第一种方式为佳,第一种方式每次开机后会将 dns-nameservers 值写入 resolv.conf 文件中。

  • 相关阅读:
    三范式
    解决Linux下乱码
    ER概念模型
    20140607
    PHP Fatal error: Class 'Yaf_Application' not found
    PHP流式读取XML文件
    php反射的使用
    wget 和curl 进行post数据
    crontab
    Leetcode OJ: Gray Code
  • 原文地址:https://www.cnblogs.com/ifantastic/p/3422277.html
Copyright © 2011-2022 走看看