linux 路由配置详情

在这里插入图片描述
添加网段路由,想要只显示U
route add -net 192.168.1.0 netmask 255.255.255.0 dev ens192
[root@ht23 k8snode]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
表示192.168.1.0/24网段能通过

添加主机路由,显示UH
route add -host 192.168.1.1 dev ens192 //添加成功,不需要指定掩码注意
[root@ht23 k8snode]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 ens192
//显示UH,表示主机192.168.1.1这台机器,可以被ens192网卡转发出去.

添加网关路由,显示UG
[root@etcd2 system]#route add default gw 10.129.55.1等同于
[root@etcd2 system]#route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.129.55.1
[root@etcd2 system]#route del default gw 10.129.55.1

[root@etcd2 system]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.129.55.1 0.0.0.0 UG 0 0 0 ens192
//表示去往任何网段的数据包即所有目的地的数据包由网关10.129.55.1通过网卡ens192来转发
//添加了一个网关 ,Flags:UG

路由配置:

1、路由转发配置
net.ipv4.ip_forward = 1 (要想路由生效需配置路由转发)
2、添加临时路由
route add -host 192.168.1.2 dev eth0
route add -host 10.20.30.148 gw 10.20.30.40
route add -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
route add default gw 192.168.1.1 添加默认路由
route del -host 192.168.1.2 dev eth0 删除一条路由

2、添加永久路由
vim /etc/sysconfig/network-scripts/route-em1
172.30.149.176/28 via 10.119.33.97 dev em1
10.1.93.231/32 via 10.122.165.254 dev em1 metric 501

猜你喜欢

转载自blog.csdn.net/qq_39412605/article/details/127984217
今日推荐