查询IP地址与网卡信息
ifconfig
或者
ip a
检查网络是否联通
ping xxx.xxx.xxx.xxx
设置静态IP地址
先查询网卡信息
ifconfig
得到如下的结果
eno1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 88:a4:c2:14:81:b3 txqueuelen 1000 (Ethernet)
RX packets 527 bytes 36496 (36.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 866 bytes 157585 (157.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
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 323096 bytes 66697687 (66.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 323096 bytes 66697687 (66.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.132.43 netmask 255.255.255.0 broadcast 192.168.132.255
inet6 240e:46c:a401:1f13:7371:c269:c750:972a prefixlen 64 scopeid 0x0<global>
inet6 240e:46c:a401:1f13:c084:6256:b76b:e32a prefixlen 64 scopeid 0x0<global>
inet6 fe80::2ed:ce74:16aa:d8da prefixlen 64 scopeid 0x20<link>
ether 4c:d5:77:61:93:9f txqueuelen 1000 (Ethernet)
RX packets 89439 bytes 87512162 (87.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64076 bytes 10228245 (10.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
网卡信息可能有多个,比如这里就有两个网卡 eno1
与wlp4s0
“inet”后面的IP地址是该网卡的IP地址,“netmask”后面的值是该网卡的子网掩码,
“ether”后面的值是该网卡的MAC地址,
“RX packets”表示该网卡接收到的数据包数量,
“TX packets”表示该网卡发送的数据包数量,
“RX errors”和“TX errors”表示该网卡接收和发送过程中发生的错误数量。
这时候选择我们想要固定的静态IP地址的网卡
ifconfig eno1 xxx.xxx.xxx.xxx(静态IP地址) netmask 255.255.255.0(网关)
注意,设置了静态IP地址不一定成功,这时候我们需要检查是否能够PING通
ping xxx.xxx.xxx.xxx(我们设置的静态IP地址)
如果不能,首先可以尝试开关网卡
sudo ifconfig eno1 down
sudo ifconfig eno1 up
如果不行,尝试重启网络服务
sudo systemctl restart NetworkManager.service
或者
sudo service NetworkManager stop
sudo service network restart