显示路由表 route route -n 实际地址

[10:41:45 root@rocky ~]#route
Kernel IP routing table
Destination(目标)     Gateway(网关,下一个路由器临近我的地址)           Genmask         Flags Metric Ref    Use Iface(接口,当前路由器要达到远程网络的出口)
default         _gateway      0.0.0.0         UG    100    0        0 eth0
default         _gateway        0.0.0.0         UG    101    0        0 eth1
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0(要到达10.0.0.0做个网络要从eth0这个网卡发出去)
172.18.0.0      0.0.0.0         255.255.0.0     U     101    0        0 eth1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

假设要去上海
Destination
上海

route 命令 设置和查看路由表都可以用 route 命令,设置内核路由表的命令格式是:

# route  [add|del] [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
其中:

add : 添加一条路由规则
del : 删除一条路由规则
-net : 目的地址是一个网络
-host : 目的地址是一个主机
target : 目的网络或主机
netmask : 目的地址的网络掩码
gw : 路由数据包通过的网关
dev : 为路由指定的网络接口

//配置完网卡信息后重新加载
[15:34:13 root@centos8] network-scripts]#nmcli connection reload

//启动网卡
nmcli connection up eth0 eth1

//查看
[15:34:39 root@centos8] network-scripts]#nmcli connection 
NAME    UUID                                  TYPE      DEVICE 
eth0    5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0   
eth1    9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
eth2    2e18e4be-a7fa-9783-73f7-046a043198be  ethernet  eth2   
virbr0  306fa505-a19a-48c8-b4c7-bde1bb8bf72e  bridge    virbr0 

//修改主机名
修改主机名为router1,为了实验路由看着方便
hostnamectl set-hostname router1

让路由器能充当路由功能

[root@centos8 network-scripts]# sysctl -a|grep ip_forward net.ipv4.ip_forward = 1 #这里改为1 net.ipv4.ip_forward_update_priority = 1 net.ipv4.ip_forward_use_pmtu = 0