Centos7配置临时路由和永久路由
首先使用route -n查看路由表route -nKernel IP routing tableDestinationGatewayGenmaskFlags Metric RefUse Iface0.0.0.01.1.1.10.0.0.0UG10000 enp5s0...
·
首先使用route -n查看路由表
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 1.1.1.1 0.0.0.0 UG 100 0 0 enp5s0f0
10.2.0.0 172.20.3.254 255.255.0.0 UG 0 0 0 enp5s0f1
然后查看工作的网卡:
ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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
2: enp5s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether f4:ce:46:b0:3e:82 brd ff:ff:ff:ff:ff:ff
inet 1.1.1.1/27 brd 139.220.242.63 scope global enp5s0f0
valid_lft forever preferred_lft forever
inet 1.1.1.31/32 scope global enp5s0f0
valid_lft forever preferred_lft forever
3: enp5s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether f4:ce:46:b0:3e:83 brd ff:ff:ff:ff:ff:ff
inet 172.20.3.64/24 brd 172.20.3.255 scope global enp5s0f1
valid_lft forever preferred_lft forever
inet 172.20.3.66/32 scope global enp5s0f1
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:74:59:1c:3e brd ff:ff:ff:ff:ff:ff
inet 10.110.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
从上面发现处于活动的网卡名称为enp5s0f0,enp5s0f1;我们为其创建对应的路由配置文件。route-enp5s0f1,因为enp5s0f0规划是默认路由出去,故不创建
vim /etc/sysconfig/network-scripts/route-enp5s0f1
10.5.0.0/16 via 172.20.3.254 dev enp5s0f1
保存退出
systemctl restart network
再次使用route -n查看
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 139.220.242.33 0.0.0.0 UG 100 0 0 enp5s0f0
10.2.0.0 172.20.3.254 255.255.0.0 UG 0 0 0 enp5s0f1
10.5.0.0 172.20.3.254 255.255.0.0 UG 0 0 0 enp5s0f1
路由表已经在里面了
添加临时路由
注意:临时路由重启网卡后路由会消失
添加一条道10.10.0.0/16的临时路由
route add -net 10.10.0.0/16 gw 172.20.3.254
route -n查看路由表:
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 139.220.242.33 0.0.0.0 UG 100 0 0 enp5s0f0
10.2.0.0 172.20.3.254 255.255.0.0 UG 0 0 0 enp5s0f1
10.5.0.0 172.20.3.254 255.255.0.0 UG 0 0 0 enp5s0f1
10.10.0.0 172.20.3.254 255.255.0.0 UG 100 0 0 enp5s0f1
路由表已经在里面了
更多推荐
已为社区贡献1条内容
所有评论(0)