Ubuntu configuration static Routing and restart effective
First method: Use the route command (add temporary route)
routes added to the host
# route add-host 192.168.1.123 Dev eth0
# route Add-host 192.168.1.123 GW 192.168.1.1
routes added to the network
# route add-net 192.168.1.123 netmask 255.255.255.0 eth0
# route add-net 192.168.1.123 netmask 255.255.255.0 GW 192.168.1.1
# route add-net 192.168.1.123 netmask 255.255.255.0 GW 192.168.1.1 eth1
# route Add-net 192.168.1.0/24 eth1
Add a default gateway
# route add default GW 192.168.1.1
Delete Route
# route Del-host 192.168.1.11 Dev eth0
# route del-net 192.168.1.123 netmask 255.255.255.0
Second method: Modify/etc/rc.local
To modify the/etc/rc.local, just note that do not uninstall "Exit 0" after
VI /etc/rc.local
Route add default GW 192.168.1.1
This will automatically include the relevant routing settings when the system is started
Note:
(1) If a system service, such as an NFS service, is started after the network service is launched, if you set up an automatic mount NFS before executing rc.local, the link here is not smooth, which will cause mount failure.
(2) If you restart the network server, then the route is invalid, this time you have to reload the file, but if you are remote operation? So, this method is not very recommended
Third method: Modify the Interfaces file
Up Route add-net 192.168.1.0 netmask 255.255.255.0 GW 192.168.1.1
You can see that the only difference between this format and the route command is that there is one more up in front
Below is a list of my interface files for reference only, for security reasons, here IP I have replaced with XX:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see Interfaces (5).
# The Loopback network interface
Auto Lo
Iface Lo inet Loopback
# The Primary network interface
Auto Eth0
Iface eth0 inet Static
Address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
Gateway xxx.xxx.xxx.xxx
Auto eth0:0
Iface eth0:0 inet Static
Address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
#dns-nameservers 202.102.224.68 202.102.227.68
Up Route add-net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx GW xxx.xxx.xxx.xxx eth0
Up Route add-net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx GW xxx.xxx.xxx.xxx eth0
Up Route add-net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx GW xxx.xxx.xxx.xxx eth0
the fourth type: in/etc/sysconfig/network
The network is added to the end of the file in the following format
VI /etc/sysconfig/network
Gateway=gw-ip or Gateway=gw-dev
Note: this way looks like it can only be used to add a default gateway , for a multi-channel network environment seems not suitable for the look
The fifth type: Write directly to the Ifcfg file
When configuring the IP address, directly write the configuration of the GATEWAY to the Ifcfg file, in the form: Gateway=gw-ip
Suitable for adding default routes
Sixth: Write to the/etc/sysconfig/static-routes file
The default in the/ETC/SYSCONIFG directory is not this file, we need to create manually, the call to this file in the following:
/etc/init.d/network:
159 # ADD Non interface-specific static-routes.
if [-f/etc/sysconfig/static-routes]; Then
161 grep "^any"/etc/sysconfig/static-routes | While read ignore args; Do
162/sbin/route add-$args
163 done
<span style= "Font-fam
This article is from the "Ops Little Boss" blog, please be sure to keep this source http://solin.blog.51cto.com/11319413/1900865
Ubuntu configuration static Routing and restart effective