Centos添加路由

一、临时添加

# 多个IP
[root@centos7 ~]# route add -net 10.1.0.0 netmask 255.255.255.0 gw 172.1.0.254
[root@centos7 ~]# route add -net 10.1.0.0/32 gw 172.1.0.254
[root@centos7 ~]# route add -net 10.1.0.0/32 dev eno1


# 单个IP
[root@centos7 ~]# route add -net 10.1.0.0 netmask 255.255.255.0 gw 172.1.0.254
[root@centos7 ~]# route add -net 10.1.0.0/24 gw 172.1.0.254
[root@centos7 ~]# route add -net 10.1.0.0/24 dev eno1

二、永久添加路由

# 方法一:利用nmcli工具
[root@centos7 ~]# nmcli con mod bond1 +ipv4.routes "10.1.0.0/20 172.1.0.254"
[root@centos7 ~]# cat ../route-bond1
ADDRESS1=10.1.0.0
NETMASK1=255.255.240.0
GATEWAY1=172.1.0.254
# 方法二:自主编写配置文件
文件格式:route-xxx,xxx为网卡名)
[root@centos7 ~]# vim ../route-xxx
10.1.0.0/20 via 172.1.0.254
10.1.0.0/20 dev bond1

## 推荐选择方法一

三、网络管理器(NetworkManager —— nmcli工具)

# 添加路由
[root@centos7 ~]# route add -net 10.1.0.0/20 gw 172.1.0.254
# 查看网卡
[root@centos7 ~]# nmcli con show
# 查看网关
[root@centos7 ~]# nmcli con show bond1  
# 写配置文件
[root@centos7 ~]# nmcli con mod bond1 +ipv4.routes "10.1.0.0/20 172.1.0.254"

四、补充

[root@centos7 ~]# route  -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.0.0        172.1.0.254     255.255.255.0   UG    0      0        0 eth0
10.2.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.3.0.0        172.2.0.254     255.255.255.0   UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值