方法1:echo "192.168.1.0/24 via 172.17.100.1" > /etc/sysconfig/network-scripts/route-eth0
[[email protected] ~]# echo "192.168.1.0/24 via 172.17.100.1" > /etc/sysconfig/network-scripts/route-eth0 [[email protected] ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 172.17.100.1 255.255.255.0 UG 0 0 0 eth0 172.17.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 172.17.100.1 0.0.0.0 UG 0 0 0 eth0 [[email protected] ~]#
方法2:
[[email protected] ~]# echo -e "ADDRESS0=192.168.1.0\nNETMASK0=255.255.255.0\nGATEWAY0=172.17.100.1" > /etc/sysconfig/network-scripts/route-eth0 [[email protected] ~]# cat /etc/sysconfig/network-scripts/route-eth0 ADDRESS0=192.168.1.0 NETMASK0=255.255.255.0 GATEWAY0=172.17.100.1 [[email protected] ~]# /etc/init.d/network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 172.17.100.240 is already in use for device eth0... [ OK ] [[email protected] ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 172.17.100.1 255.255.255.0 UG 0 0 0 eth0 172.17.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 172.17.100.1 0.0.0.0 UG 0 0 0 eth0 [[email protected] ~]#
时间: 2024-10-20 02:54:17