ubuntu configure a static route

Learning linux, you may encounter problems configuring static routing, here we will introduce the solution to the problem of static routing configuration linux, out here and share with you. There are now five facilities, PC1 then ROUT1, ROUT1 followed ROUT2, ROUT2 followed ROUT3, ROUT3 followed PC2, topology below:

□————○————○————○————□

PC1      ROUT1     ROUT2     ROUT3      PC2

Linux static routing IP address of the device five were:
PC1 192.168.1.88/24
ROUT1 192.168.1.128/24 192.168.2.128/24
ROUT2 192.168.2.66/24 192.168.3.66/24
ROUT3 192.168.3.100/24 192.168.4.33/ 24-
PC2 192.168.4.66/24

PC1 is configured as follows:
#ifconfig eth0 192.168.1.88 Netmask 255.255.255.0
#route the Add default GW 192.168.1.128

ROUT1 configured as follows:
#ifconfig eth0 192.168.1.128 Netmask 255.255.255.0
#ifconfig eth0: 192.168.2.128 Netmask 255.255.255.0. 1
#route the Add -net 192.168.4.0/24 GW 192.168.2.66

ROUT2 configured as follows:
#ifconfig eth0 192.168.2.66 Netmask 255.255.255.0
#ifconfig eth0: 192.168.3.66 Netmask 255.255.255.0. 1
#route the Add -net 192.168.1.0/24 GW 192.168.2.128
#route the Add -net 192.168.4.0/24 gw 192.168.3.100

ROUT3 configured as follows:
#ifconfig eth0 192.168.3.100 Netmask 255.255.255.0
#ifconfig eth0: 192.168.4.33 Netmask 255.255.255.0. 1
#route the Add -net 192.168.1.0/24 GW 192.168.3.66

PC2 configured as follows:
#ifconfig eth0 192.168.4.66 Netmask 255.255.255.0
#route the Add default GW 192.168.4.33
such PC1 PC2 able to ping a.

Note: The
above three is here replaced by three PC. Instead of a computer, you must enable the computer to the IP forwarding function, change the / proc / sys / net / ipv4 / ip_forward the contents of 1 (the default is 0), complete with the following command
#e cho 1> / proc / sys / net / ipv4 / ip_forward
network after restart, the above file is automatically changed to 0
to add a few commands:
1, remove the default route
#route del default
2, static routing Linux Check
#route -n
3, setting specifies network routing
#route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.6.66
or
#route the Add -net 192.168.3.0/24 gw 192.168.6.66
4, delete the specified network route
#route del -net 192.168.3.0 netmask 255.255.255.0
or
# route del -net 192.168.3.0/24
above to introduce the linux configure static routes.

nternet------(eth1)router1(eth2)------(eth1)router2(eth0)------(eth0)router3(eth1)------(eth0)pc

The above is my network topology in which a router is used to connect an external network of a linux machine, drawing all routers are ordinary pc machine, these pc ubuntu desktop systems are installed, in addition to the rightmost pc, rest the pc have installed three NIC (where a spare).

As the network card is configured with Redhat Debian-based system is very different, Redhat is placed in / etc / sysconfig / network-scripts directory of a lot of files inside. The network card configuration Debian system is the existence of / etc / network / interfaces This file is inside, and no matter how much you have network cards, regard the system configuration all on this file. Here's a look at the contents of this document.

First, we look router1 configuration:

search all of it to auto so 
iface search all of the inet loopback
iface inet6 search all of loopback
auto eth0
iface eth0 inet static
      address 192.168.2.1
      network 192.168.2.0
      netmask 255.255.255.0
      broadcast 192.168.2.255
      up route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.2.2 dev eth0
      down route del -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.2.2 dev eth0
      up route add -net 192.168.4.0 netmask 255.255.255.0 gw 192.168.2.2 dev eth0
      down route del -net 192.168.4.0 netmask 255.255.255.0 gw 192.168.2.2 dev eth0
iface eth0 inet6 static
      address 2000:2::1
      netmask 64
      up route -A inet6 add 2000:3::/64 gw 2000:2::2
      up route -A inet6 add 2000:4::/64 gw 2000:2::2
      down route -A inet6 2000: 3 :: / 64 gw, 2000: 2 :: 2
      down route -A inet6 2000: 4 :: / 64 gw, 2000: 2 :: 2
auto eth1
iface eth1 inet dhcp

In the above configuration,

DESCRIPTION auto lo interfaces with the interface eth0 is automatically configured at system startup; lo is a local loop (Loopback) address, there are provided two v4 and v6 loopback; static Description This is a static IP configuration; configuration behind in that role when the interface is enabled, add two static routes, and when the interface is disabled, delete the two routing configuration. As to configure routing wording, like the route command under cmd line (except up down beginning).

Internet connection is behind the eth1 outside, so use dhcp connected with the outside.

After the router with a good document, but also enable their own ip forwarding, which requires them to enter into this file /etc/sysctl.conf, adding net.ipv4.ip_forward = 1, and net.ipv6.default.ip_forward = 1 two sentences. After the exit, and then sysctl -p /etc/sysctl.conf. This opens ip forwarding.

After with a good forward, but also can not be made online, but between the router has been able to ping each other, which you need to configure dns server on each router, you need to add the appropriate information in /etc/resolv.conf:

search test.com
nameserver *.*.*.*

After a few behind such router can find router1 according to their dft gw and get in touch with the external network and connect to the Internet

If you go with multicast ipv6, which will help mrd6 this software to achieve the specific configuration method is very simple, you just put deb packages installed, and then configure mrd.conf this file on the line. Running time as long as the file has mrd.conf file folder sudo mrd6 ok.

The remaining router configuration router1 probably the same, but with this difference pc

 

Restart Network Configuration

sudo /etc/init.d/networking restart

Guess you like

Origin www.cnblogs.com/surplus/p/11441515.html
Recommended