赞
踩
目录
Ubuntu 16.04.5 LTS、Ubuntu 20.04.6 LTS
- ifconfig
- ifconfig -a
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
-
- auto enp159s0f0
- iface enp159s0f0 inet static
- address 192.168.0.10
- netmask 255.255.255.0
- gateway 192.168.0.1
- dns-nameservers 10.0.0.1
- systemctl status networking
- systemctl restart networking
如果状态日志中出现找不到enp159s0f0的报错,请检查配置文件中的enp159s0f0是否书写正确!
vim /etc/netplan/01-netcfg.yaml
- network:
- version: 2
- renderer: networkd
- ethernets:
- eno1:
- dhcp4: no
- addresses: [192.168.0.20/24]
- gateway4: 192.168.0.1
- nameservers:
- search: [ubuntu]
- addresses:
- - "192.168.0.20"
netplan apply
如果IP地址没有变化,请确认网卡是否正确,一般是有IPv6地址的网卡!
- cd /etc/sysconfig/network-scripts
- ls
- vim ifcfg-对应网卡
- TYPE=Ethernet
- PROXY_METHOD=none
- BROWSER_ONLY=no
- BOOTPROTO=none
- DEFROUTE=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=yes
- IPV6_AUTOCONF=yes
- IPV6_DEFROUTE=yes
- IPV6_FAILURE_FATAL=no
- IPV6_ADDR_GEN_MODE=stable-privacy
- NAME=enp125s0f0
- UUID=5ff52bad-2bdb-3d7f-a8b2-57a9bafasdfg
- ONBOOT=yes
- AUTOCONNECT_PRIORITY=-999
- DEVICE=enp125s0f0
- IPADDR=192.168.0.30
- PREFIX=22
- GATEWAY=192.168.0.1
- DNS1=10.0.0.1
- DNS2=10.0.0.2
- DNS3=10.0.0.3
- IPV6_PRIVACY=no
- service NetworkManager restart
- nmcli c reload
- nmcli c up enp125s0f0
如果IP地址在子网掩码范围内但不是设置的值,请确认 BOOTPROTO 参数配置是否正确!
- TYPE=Ethernet
- PROXY_METHOD=none
- BROWSER_ONLY=no
- BOOTPROTO=dhcp
- DEFROUTE=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=yes
- IPV6_AUTOCONF=yes
- IPV6_DEFROUTE=yes
- IPV6_FAILURE_FATAL=no
- IPV6_ADDR_GEN_MODE=stable-privacy
- NAME=enp125s0f0
- UUID=5ff52bad-2bdb-3d7f-a8b2-57a9bafasdfg
- ONBOOT=yes
- AUTOCONNECT_PRIORITY=-999
- DEVICE=enp125s0f0
- service NetworkManager restart
- nmcli c down enp125s0f0
- nmcli c show
如果出现 No suitable device found for this connection 错误,则说明修改已生效,enp125s0f0已不存在!
- ping 192.168.0.10
- ping 192.168.0.20
如果IP地址正常但无法ping通,请确认:
联网的网口MAC地址与修改的网卡MAC地址是否对应
是否存在两个网卡IP地址相同,可使用以下命令启用/禁用网卡:
- # 启用网卡
- ifconfig enp125s0f1 up
- # 禁用网卡
- ifconfig enp125s0f1 down
参考资料:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。