CentOS/RHEL Linux 設定IP轉址與設定調整一臺主機多網卡之靜態route優先權
1. sudo vim /etc/sysctl.conf to modify net.ipv4.ip_forward
or
sudo sed -i 's/net.ipv4.ip_forward=0/ net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sysctl -p
2. permanent setting in /etc/sysconfig/newtork-scripts/route-eXXXX if nm-bond0 is default router
touch /etc/sysconfig/network-scripts/route-enp2s0
echo '192.168.2.0/24 via 192.168.1.1 dev nm-bond0' >> /etc/sysconfig/network-scripts/route-enp2s0
$ route -n #route
$ sudo route del default dev nm-bond0
$ sudo route del default dev enp2s0
$ sudo route add default via 192.168.1.1 netmask 0.0.0.0 dev nm-bond0 metric 0
$ sudo route add default via 192.168.1.1 netmask 0.0.0.0 dev enp2s0 metric 1
將 script 加入 /etc/rc.local,讓開機即可改變
#Centos Linux 7
nmcli connection show dev enp5s0 | grep ipv4
nmcli connection modify enp5s0 ipv4.route-metric 0
nmcli connection modify enp2s0 ipv4.route-metric 1
nmcli connection up enp5s0
nmcli connection up enp2s0
參考
https://unix.stackexchange.com/questions/344974/how-can-i-make-changes-to-the-network-routing-metric-permanently
https://www.tecmint.com/configure-network-connections-using-nmcli-tool-in-linux/