Ubuntu配置IP
描述
由於需要,有時候需要給服務器/PC配置靜態的IP,爲了以後查關鍵字方便,在博客這裏記一下。
操作
1. DHCP方式配置網卡
配置文件:
$ sudo vim /etc/network/interfaces
修改:
# The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp
2. 配置靜態IP地址
仍然修改相同的配置文件:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
#network 192.168.3.0
#broadcast 192.168.3.255
其中的IP地址和網關等,填寫自己的地址等信息。
3. 配置DNS
配置文件:
$ sudo vim /etc/resolv.conf
添加:
nameserver 8.8.8.8
nameserver 10.8.4.4
nameserver 10.8.8.8
DNS也可以填寫自己的localhost,或者選擇google的DNS等,一個或多個均可。
4. 配置文件生效
配置完對應的配置文件,需要使其生效:
$ sudo /etc/init.d/networking restart