How to set a default route route hosts (mnemonic only) Ma Lian WA, MA wa

Source: Internet
Author: User

Ways to add routes under Linux:
One: Use the route command to add
Routes added using the route command, the machine restarts, or the network card restarts, the route is invalidated, by:
Routes added to the host
# route add–host 192.168.168.110 Dev eth0
# route Add–host 192.168.168.119 GW 192.168.168.1
Routes added to the network
# route add–net IP netmask MASK eth0
# route add–net IP netmask MASK GW IP
# route Add–net ip/24 eth1
Add a default gateway (MA Lian WA)
# route add default GW IP
Delete route
# route del–host 192.168.168.110 Dev eth0
Two: The method of setting the permanent route under Linux:
1. Add in/etc/rc.local

Route add-net 192.168.3.0/24 Dev eth0
Route add-net 192.168.2.0/24 GW 192.168.3.254

2. Add to end in/etc/sysconfig/network
Method: Gateway=gw-ip or Gateway=gw-dev

Any net x.x.x.x/24 GW Y.y.y.y



-----------------------

Abnormal:

The NIC information is reconfigured in the virtual machine, but access to the other network segment in the LAN is not available.

Reason:

Although new gateway information has been added to the NIC information, it is not set to the default in the static routing list (ROUTE-N).

Solve:

Add route (temporary, permanent)

Static route modification command under Linux
Method One:
Add route
Route add-net 192.168.0.0/24 GW 192.168.0.1
Route Add-host 192.168.1.1 Dev 192.168.0.1
Delete route
Route del-net 192.168.0.0/24 GW 192.168.0.1

Add Add route
del Delete route
-net setting a route to a network segment
-host setting a route to a host
GW Export Gateway IP address
Dev Egress Gateway Physical device name

Add default route

Route add default GW 192.168.0.1
Default route one is enough.

Route-n Viewing the routing table

Method Two:
Add route
IP route add 192.168.0.0/24 via 192.168.0.1
IP route add 192.168.1.1 dev 192.168.0.1
Delete route
IP route del 192.168.0.0/24 via 192.168.0.1

Add Add route
del Delete route
Via Gateway egress IP Address
Dev Gateway Export Physical device name

Add default route
IP route add default via 192.168.0.1 dev eth0
Via 192.168.0.1 is my default router

Viewing routing information
IP route

Save the routing settings so that they are valid after a network restart
Create a file named Route-eth0 under the/etc/sysconfig/network-script/directory
Vi/etc/sysconfig/network-script/route-eth0
Add content in this file in the following format

192.168.1.0/24 via 192.168.0.1


Restart network authentication

Attached: How to set up a permanent route under Linux:
1. Add in/etc/rc.local
Method:
Route add-net 192.168.3.0/24 Dev eth0
Route add-net 192.168.2.0/24 GW 192.168.2.254
2. Add to end in/etc/sysconfig/network
Method: Gateway=gw-ip or Gateway=gw-dev
3./etc/sysconfig/static-routes: (Create a file manually without static-routes)
Any net 192.168.3.0/24 GW 192.168.3.254
Any net 10.250.228.128 netmask 255.255.255.192 GW 10.250.228.129
4. Turn on IP forwarding:
# echo "1" >/proc/sys/net/ipv4/ip_forward (temporary)
# vi/etc/sysctl.conf-net.ipv4.ip_forward=1 (permanently on)
If adding a route in Rc.local causes NFS to not mount the problem automatically, it is best to use the Static-routes method. Both the reboot system and the service network restart will take effect
In the order of Linux boot, Rc.local inside the content is in Linux all services are started, and finally executed, that is, the contents of this is executed after Netfs, that is to say, when the Netfs startup, the static route on the server is not added, so netfs mount can not be successful.
What is the Static-routes file, this is a file that is called when the network script executes, and the file is placed in the/etc/sysconfig directory, where it is located in the network script:
# Add non interface-specific static-routes.
if [-f/etc/sysconfig/static-routes]; Then
grep "^any"/etc/sysconfig/static-routes | While read ignore args; Do
/sbin/route add-$args
Done
Fi
As you can see from this script, this is the way to add static routes, and Static-routes's notation is
Any net 192.168.0.0/16 GW gateway IP
In this case, the route is added automatically when the network script is started, and because the network is started in front of the netfs, it is naturally normal to mount NFS.
Thus, if you need to add a static route, using the Static-routes file is better than using rc.local, and when the network configuration is changed, the corresponding static route can be added automatically, However, if you use Rc.local, when you restart the network service, the originally added static route disappears.

Example virtual machine Ubuntu cannot surf the internet

It should be 0.0.0.0, so that all the packages are masked, use the following command:
#route del Default (to remove the defaults route)
#route Add default GW 172.16.52.1
Finally, this routing table is normal.
[Email protected]:~# netstat-r
Kernel IP Routing Table
Destination Gateway genmask Flags MSS Window Irtt Iface
172.16.52.0 * 255.255.255.0 U 0 0 0 eth0
Default 172.16.52.1 0.0.0.0 UG 0 0 0 eth0

How to set a default route route hosts (mnemonic only) Ma Lian WA, MA wa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.