0xTrustTryEP

Just do it, deeply...

Follow me on GitHub

Ubuntu配置静态ip

write by donaldhan, 2018-11-11 21:37

首先设置VMware workstation为NAT模式,然后设置NAT,查看网关,子网掩码,子网ip等信息,之后配置静态ip会用到,之后点击确定保存以上设置;

然后查看网卡,使用ifconfig,如图所示,网卡名称为eno16777736。

donaldhan@ubuntu:~$ ifconfig
eno16777736 Link encap:Ethernet  HWaddr 00:0c:29:11:70:73  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:34 errors:0 dropped:0 overruns:0 frame:0
          TX packets:131 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5700 (5.7 KB)  TX bytes:23827 (23.8 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1332 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1332 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:102291 (102.2 KB)  TX bytes:102291 (102.2 KB)

配置静态ip,修改/etc/network/interfaces,增加如下配置

root@ubuntu:~# vim /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# 配置环路地址
auto lo
iface lo inet loopback
## 网卡名
auto eno16777736
# 配置静态ip
iface eno16777736 inet static
# 配置动态ip
#inface eno16777736 inet dhcp
address 192.168.5.128
netmask 255.255.255.0
gateway 192.168.5.2
~                     

注意:文件路径不能错,错的话ip配置将不会生效。

配置DNS, vim /etc/resolvconf/resolv.conf.d/base

root@ubuntu:~# vim /etc/resolvconf/resolv.conf.d/base

root@ubuntu:~# cat /etc/resolvconf/resolv.conf.d/base
114.114.114.114
223.5.5.5
8.8.8.8
root@ubuntu:~#

这里我配置了多个DNS,如图所示,114.114.114.114是国内移动、电信和联通通用的DNS,8.8.8.8是Google公司提供的DNS,该地址是全球通用,223.5.5.5 为阿里的DNS。

执行resolvconf -u将DNS配置更新到/etc/resolv.conf中 root@ubuntu:~# resolvconf -u

注意:若修改/etc/resolv.conf的话,最好同时还修改/etc/resolvconf/resolv.conf.d/base,因为每次重启,后者会向前者更新,若后者没有想过配置,DNS配置会失效

重启网络,使配置生效:

/etc/init.d/networking restart

使用ifconfig查看配置是否生效

root@ubuntu:/etc/network# ifconfig
eno16777736 Link encap:Ethernet  HWaddr 00:0c:29:11:70:73  
          inet addr:192.168.5.128  Bcast:192.168.5.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe11:7073/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3314 (3.3 KB)  TX bytes:32177 (32.1 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1740 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1740 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:132659 (132.6 KB)  TX bytes:132659 (132.6 KB)