标签:round state family conf systemctl ifcfg pad ipad vim
复制一份网卡配置文件命名为ifcfg-ens192:1
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens192 ifcfg-ens192:1
将增加的IP修改如ifcfg-ens192:1中
vim ifcfg-ens192:1
DEVICE="ens192:1"
ONBOOT="yes"
IPADDR=192.168.160.160
NETMASK=255.255.255.0
GATEWAY=192.168.160.1
此时systemctl restart network 重启网卡,即可看到新添加的IP地址
[root@ctl]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:43:00:81 brd ff:ff:ff:ff:ff:ff
inet 172.168.1.100/16 brd 172.168.255.255 scope global ens192
valid_lft forever preferred_lft forever
inet 172.168.1.101/32 scope global ens192
valid_lft forever preferred_lft forever
inet 192.168.160.160/24 brd 192.168.160.255 scope global ens192:1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe43:81/64 scope link
valid_lft forever preferred_lft forever
遇到ping不出去的情况需要检查系统的路由设置
[root@ctl] ip route del default 删除原先的默认路由
[root@ctl] vim /etc/sysconfig/network 修改配置文件添加以下两行
NETWORKING=YES
GATEWAY=192.168.160.1 网关地址
重启网卡systemctl restart network,然后ip route看到默认路由生效
[root@ctl]# ip route
default via 192.168.160.1 dev ens192
169.254.0.0/16 dev ens192 scope link metric 1002
169.254.0.0/16 dev ens224 scope link metric 1003
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.168.0.0/16 dev ens192 proto kernel scope link src 172.168.1.100
192.168.160.0/24 dev ens192 proto kernel scope link src 192.168.160.160
问题1:如果修改配置文件后不生效,恢复原先默认路由的情况 解决方法是检查生效的网卡配置文件,是否残留原先网关信息
问题2:如果修改配置文件不生效,不显示默认路由,检查默认路由是否正确,检查系统是否存在该网段
标签:round state family conf systemctl ifcfg pad ipad vim
原文地址:https://www.cnblogs.com/dongchuanhua/p/12059572.html