第一步:找到对应的网卡名称
root@ubuntu:~# ifconfig
root@ubuntu:~# ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:c8:c1:53
inet addr:192.168.1.129 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec8:c153/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:101322 errors:0 dropped:0 overruns:0 frame:0
TX packets:71624 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:118412908 (118.4 MB) TX bytes:14883684 (14.8 MB)
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:182 errors:0 dropped:0 overruns:0 frame:0
TX packets:182 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:13531 (13.5 KB) TX bytes:13531 (13.5 KB)
root@ubuntu:~#
找到网卡的名称:ens33
第二步:修改网络配置,可以直接拷贝如下配置
auto ens33 //网卡
iface ens33 inet static //设置IP为静态的
address 192.168.1.129 //设置静态的IP地址
netmask 255.255.255.0 //设置子网掩码
gateway 192.168.1.1 //设置网关地址
dns-nameserver 8.8.8.8 //设置DNS解析
root@ubuntu:~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
#auto lo
#iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.1.129
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 8.8.8.8
~
"/etc/network/interfaces" 17L, 398C
第三步:重启网络
root@ubuntu:~# sudo /etc/init.d/networking restart
这样我们的Ubuntu系统就有了静态的IP,重启系统后发现IP地址始终是我们设置的静态IP.