最近项目用到route这块的东西,需要把不同的ip网段指向ip网关
技术博客 http://idea.coderyj.com/
vim /etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
routes:
- to: 172.16.0.0/16
via: 192.168.1.1
metric: 50
- to: 10.0.0.0/8
via: 192.168.1.1
metric: 100
说明
to
是那个网段的ip
,via
是走的哪个网关metric
是优先级 默认100 值越小优先级越大
sudo netplan apply
route -n
echo "172.18.6.0/24 via 172.16.1.1 dev enp3s0" >> /etc/sysconfig/network-scripts/route-enp3s0
enp3s0
是你网卡名称, 后面的route-enp3s0
更换成你的网卡名称即可
service network restart
route -n
sudo ip route add 172.18.6.0/24 via 172.16.1.1 dev enp2s0
route add -net 172.18.6.0/24 gw 172.16.1.1