1. 获取网卡名称
在终端中输入:
$ ifconfig -a
enp4s0f0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 20:6a:8a:54:0e:73 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 30463 bytes 6013652 (5.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30463 bytes 6013652 (5.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 20:7c:8f:75:a3:ec txqueuelen 1000 (Ethernet)
RX packets 421969 bytes 507325951 (483.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 348498 bytes 52749595 (50.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
网卡名称即为:enp4s0f0
和 wlp3s0
(无线网卡)
2. 添加IP地址
在 /etc/network/interfaces
中添加内容:
auto enp4s0f0
iface enp4s0f0 inet static(dhcp为动态)
address 192.168.8.100
netmask 255.255.255.0
gateway 192.168.8.2
dns-nameserver 119.29.29.29
dns-nameserver 119.29.29.29 这句一定需要有,因为以前是DHCP解析,所以会自动分配DNS 服务器地址。
而一旦设置为静态IP后就没有自动获取到DNS服务器了,需要自己设置一个设置完重启电脑后,/etc/resolv.conf
文件中会自动添加 nameserver 119.29.29.29
3. 重启网络
sudo /etc/init.d/networking restart
网友评论