Linux系统的网卡路由配置

一、查看系统路由

[root@control ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.3.254   0.0.0.0         UG    103    0        0 ens161
10.88.0.0       0.0.0.0         255.255.0.0     U     0      0        0 cni0
192.168.3.0     0.0.0.0         255.255.255.0   U     103    0        0 ens161
192.168.3.254   0.0.0.0         255.255.255.255 UH    0      0        0 ens161
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

二、激活网卡

1.查看所有物理网卡

[root@control ~]# nmcli device 
DEVICE        TYPE      STATE         CONNECTION 
ens161        ethernet  connected     ens161     
cni0          bridge    connected     cni0       
virbr0        bridge    connected     virbr0     
ens160        ethernet  disconnected  --         
vethbf044fd9  ethernet  unmanaged     --         
lo            loopback  unmanaged     --         
virbr0-nic    tun       unmanaged     --

2.连接新增网卡

[root@control ~]# nmcli connection up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)

3.查看IP

ifconfig ens160

三、系统的路由管理

1.添加一条网关路由

route add -net 0.0.0.0 netmask 255.255.255.255 dev ens37  

2.设置默认网关

route add default gw 192.168.243.2
[root@192 user]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         255.255.255.255 UH    0      0        0 ens37
0.0.0.0         192.168.243.2   0.0.0.0         UG    0      0        0 ens37
0.0.0.0         192.168.3.254   0.0.0.0         UG    100    0        0 ens33
10.88.0.0       0.0.0.0         255.255.0.0     U     0      0        0 cni-podman0
192.168.3.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.243.0   0.0.0.0         255.255.255.0   U     101    0        0 ens37

3.删除默认网关

route del default gw 192.168.243.2

4.使用route命令删除静态路由

route del -net 192.168.1.0 netmask 255.255.255.0 dev ens37

四、配置路由优先级

1.多个网关存在时,无法上网

[root@192 user]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         255.255.255.255 UH    0      0        0 ens37
0.0.0.0         192.168.243.2   0.0.0.0         UG    0      0        0 ens37
0.0.0.0         192.168.3.254   0.0.0.0         UG    100    0        0 ens33
10.88.0.0       0.0.0.0         255.255.0.0     U     0      0        0 cni-podman0
192.168.3.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.243.0   0.0.0.0         255.255.255.0   U     101    0        0 ens37
[root@192 user]# ping www.baidu.com
^C
[root@192 user]# ping www.baidu.com -c4
PING www.a.shifen.com (112.80.248.76) 56(84) bytes of data.
From 192.168.243.140 (192.168.243.140) icmp_seq=1 Destination Host Unreachable
From 192.168.243.140 (192.168.243.140) icmp_seq=2 Destination Host Unreachable
From 192.168.243.140 (192.168.243.140) icmp_seq=3 Destination Host Unreachable
From 192.168.243.140 (192.168.243.140) icmp_seq=4 Destination Host Unreachable

--- www.a.shifen.com ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 2999ms
pipe 4
[root@192 user]# 

2.添加路由时指定优先级

[root@192 user]# ip route add default via 192.168.243.2 metric 99
[root@192 user]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         255.255.255.255 UH    0      0        0 ens37
0.0.0.0         192.168.243.2   0.0.0.0         UG    0      0        0 ens37
0.0.0.0         192.168.243.2   0.0.0.0         UG    99     0        0 ens37
0.0.0.0         192.168.3.254   0.0.0.0         UG    100    0        0 ens33
10.88.0.0       0.0.0.0         255.255.0.0     U     0      0        0 cni-podman0
192.168.3.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.243.0   0.0.0.0         255.255.255.0   U     101    0        0 ens37

3.添加某条静态路由

[root@192 user]# ip route add 192.168.120.0/24 via 192.168.243.2
[root@192 user]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.243.2   0.0.0.0         UG    0      0        0 ens37
0.0.0.0         192.168.243.2   0.0.0.0         UG    99     0        0 ens37
0.0.0.0         192.168.3.254   0.0.0.0         UG    100    0        0 ens33
10.88.0.0       0.0.0.0         255.255.0.0     U     0      0        0 cni-podman0
192.168.3.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.120.0   192.168.243.2   255.255.255.0   UG    0      0        0 ens37
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.243.0   0.0.0.0         255.255.255.0   U     101    0        0 ens37

4.删除静态路由

ip route del default  via 192.168.243.2

5.指定上网出口网关优先级

[root@192 user]# ip route add default via 192.168.3.254  metric 98
[root@192 user]# ping www.baidu.com
PING www.a.shifen.com (112.80.248.76) 56(84) bytes of data.
64 bytes from 112.80.248.76 (112.80.248.76): icmp_seq=1 ttl=55 time=32.3 ms
64 bytes from 112.80.248.76 (112.80.248.76): icmp_seq=2 ttl=55 time=33.0 ms
64 bytes from 112.80.248.76 (112.80.248.76): icmp_seq=3 ttl=55 time=34.0 ms
64 bytes from 112.80.248.76 (112.80.248.76): icmp_seq=4 ttl=55 time=34.2 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 32.395/33.442/34.268/0.782 ms
[root@192 user]# 

5.永久配置静态路由参考博文链接

【Linux网络配置实战】服务器Network静态路由配置

五、网卡的配置

1.修改IP

[root@node1 ~]# nmcli connection modify ens224-con224 ipv4.addresses 192.168.8.11/24 ipv4.gateway 192.168.8.1 ipv4.dns 192.168.8.1 ipv4.method manual 
[root@node1 ~]# nmcli connection reload 
[root@node1 ~]# nmcli connection up ens224-con224 

2.添加网卡IP

[root@node1 ~]# nmcli connection add ifname ens224 type ethernet con-name ens224-con224 ipv4.addresses  192.168.8.11/24 ipv4.gateway 192.168.8.1 ipv4.dns 192.168.8.1 ipv4.method manual
[root@node1 ~]# nmcli connection reload 
[root@node1 ~]# nmcli connection up ens224-con224 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@node1 ~]# 


3.给网卡配置多个IP

nmcli connection modify ens224-con224 +ipv4.addresses 192.168.8.111/24
[root@node1 ~]# nmcli con up ens224-con224 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
[root@node1 network-scripts]# ip addr show ens224
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet 192.168.8.111/24 brd 192.168.8.255 scope global secondary noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::1344:2c57:66a9:99a6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@node1 network-scripts]#

六、ss命令

[root@192 user]# ss -tunlp |grep 80
udp    UNCONN     0      0         *:807                   *:*                   users:(("rpcbind",pid=8696,fd=10))
udp    UNCONN     0      0        :::807                  :::*                   users:(("rpcbind",pid=8696,fd=11))
[root@192 user]# netstat -tunlp |grep 80
udp        0      0 0.0.0.0:807             0.0.0.0:*                           8696/rpcbind        
udp6       0      0 :::807                  :::*                                8696/rpcbind
  • 6
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Windows 网卡策略路由是一种用于配置和管理网络流量的功能。它允许管理员基于特定条件来定义数据包的路由路径。 通过网卡策略路由,管理员可以按照自己的需求将流量分配给不同的网络接口。例如,当使用多个网络接口时,管理员可以根据优先级或其他条件决定哪个接口应该用于特定类型的流量。这可以增加网络的容量,并提高网络性能和可靠性。 在Windows操作系统中,可以通过命令行工具如route命令或者Windows管理控制台来配置网卡策略路由。管理员可以设置路由表、路由规则和策略顺序来定义流量的路由路径。 首先,管理员可以通过路由表来定义特定目标网络路由路径。路由表由目标网络、子网掩码、网关和接口组成,指定了数据包应该被发送到哪个网关和接口。管理员可以添加、修改或删除路由表中的路由项,以控制流量的路由路径。 其次,管理员可以通过路由规则来指定流量的路由策略。路由规则基于特定条件来匹配数据包,并决定将其发送到哪个网关和接口。管理员可以配置多个路由规则,使用不同的条件和优先级来定义不同类型的流量的路由路径。 最后,管理员可以通过策略顺序来指定路由规则的优先级。策略顺序确定了路由规则的应用顺序,优先级高的规则会在优先级低的规则之前被应用。这样,管理员可以根据特定需求确保流量按照预期的方式进行路由。 总之,Windows 网卡策略路由是一种强大的功能,可以根据特定条件和需求来配置和管理网络流量的路由路径。通过使用网卡策略路由,管理员可以灵活地控制流量的分配,提高网络的性能和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖有缘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值