Configuring Routers in Linux

Source: Internet
Author: User

Configure the Router

In the process of learning Linux , the network configuration is necessary, how to Configure the routing network on the Linux system, so as to ensure that not the same network between the two hosts can communicate.

First, network segment settings

The first thing to note is that our experiment was carried out on five virtual machines, and the operating system is Linux system. Of these, two virtual machines are hosts a,B, and three other virtual machines. After determining the capabilities and roles of different hosts, we need to configure their network cards first. Its specific configuration is as follows:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/06/B6/wKiom1m8xn2yK7W9AADGRMeP8H0542.png "title=" 2.PNG "Style=" float:left; "alt=" Wkiom1m8xn2yk7w9aadgrmep8h0542.png "/>

when dividing the network segment, you need to be careful not to divide the error, or the latter will appear in the direct network Ping does not pass the phenomenon. The network segments of different network cards of the same route are different, so special distinction should be made between network cards and network segments.

Second, view network card information

use the ifconfig command to see the name and IP address of the network card , and if the NIC name is not standard eth0 and eth1, vim/etc/udev/ Rules.d/70-persistent-net.rules View and modify the corresponding network card information, and /etc/sysconfig/network-scripts/ in the file information consistent, However, it is best to standardize the configuration for ease of administration.

Third, modify the configuration file

Vim/etc/sysconfig/network-scripts/[ General and Nic name with the same name]

Note: You do not need to add a gateway, only the configuration - good IP address, because the router in the routing table in lieu of the function of the gateway. Because a router has two interfaces, if network-scripts does not have a corresponding configuration file, it is added manually.

3.1 IP,MASK,Gw,DnsRelated configuration Files

/etc/sysconfig/network-scripts/ifcfg-iface

Routing-related configuration files:

/etc/sysconfig/network-scripts/route-iface

/etc/sysconfig/network-scripts/ifcfg-iface:

Detailed Description:

Onboot: Whether this device is activated at system boot time

type: interface types; common Ethernet,bridge

UUID: Unique identification of the device

IPADDR: Specify IP address

NETMASK: Subnet mask

Gateway: Default Gateways

DNS1: The first DNS server points to a

DNS2: The second DNS server points to a

Userctl: Whether a normal user can control this device

Peerdns: If the value of Bootproto is "DHCP", allows the dhcpserver assigned DNS server to direct the information to the/etc in the/resolv.conf file

Description Reference:

/usr/share/doc/initscripts-9.49.30/sysconfig.txt

device: Devices to which this profile applies

HWADDR: MAC address ofthe corresponding device

Bootproto: Address Configuration protocol used when activating this device, common dhcp, static, none, BOOTP

nm_controlled:nm is a shorthand for NetworkManager , does this NIC accept NM control; CentOS6 recommended as "No"

3.2DisabledNetworkManagerService

Service Networkmanagerstop

The NetworkManager service in CENTOS6 can affect the configuration, thereby making an error and disabling it.

Iv. Adding routes

Route add–net10.3.0.0/16 GW 10.2.0.201 Dev eth1(add network route)

If a route exists in addition to the target network network different IDs, the same situation can be combined into a default route (that is, 0.0.0.0)

4.1Routing Management Commands

View:route-n

added:routeadd

Route add [-net|-host] target [netmask Nm] [Gwgw][[dev] If]

target:192.168.1.3 Gateway:172.16.0.1

# route add-host192.168.1.3 gw172.16.0.1 Dev eth0

target:192.168.0.0 Gateway:172.16.0.1

# route add-net192.168.0.0 netmask 255.255.255.0 gw172.16.0.1 Dev eth0

# route add-net192.168.0.0/24 gw172.16.0.1 Dev eth0

v. Testing5.1Trace Route

Traceroute 10.4.0.100/tracepath 10.4.0.100

5.2Dynamic Trace Routing

MTR 10.4.0.100

Six, start the forwarding function

Echo 1 >/proc/sys/net/ipv4/ip_forward

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/A5/66/wKioL1m8xzDjewXyAAALHpqif6M185.png "style=" Background:url ("/e/u261/themes/default/images/word.gif") no-repeat center;border:1px solid #ddd; "alt=" Spacer.gif " Width= "520" height= "title=" 1.PNG "/>

The above content is just about the process of configuring routing, but it will involve a lot of corresponding knowledge, in order to facilitate the summary, not explained in detail above, next will be involved in the knowledge to do the following summary:

Ipconfiguration of the addressI. Modification of documents

1,vim/etc/sysconfig/network-scripts/ifcfg-eth0(preferably with the same name of the NIC can also be different)

device=[ device name ](must match the physical NIC)

Bootproto=dhcp|static |none (DHCP means auto get, both of which are manually assigned )

Ipaddr=172.17.0.123

netmask=255.255.0.0

[ or use prefix=16 to represent the subnet mask, and select one of the two above ]

gateway=172.17.0.1 ( address of an interface of a router )

dns1=114.114.114.114

dns2=8.8.8.8

2.configure another file for the gateway

[[Email protected]~]# vim/etc/sysconfig/network

Networking=yes

Hostname=muyongxue6

gateway=172.17.0.1

(when two files have a different gateway configuration, /etc/sysconfig/network-scripts/ifcfg-eth0 the configuration in the file is subject to )

Second, see if the gateway is configured successfully

1,route–n

[[Email protected]]# route-n

Kernel iprouting Table

Destination Gateway genmask Flags Metric Ref use Iface

192.168.163.0 0.0.0.0 255.255.255.0 U 1 0 0 eth2

172.17.0.0 0.0.0.0 255.255.0.0 U 1 0 0 Eth3

0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 Eth3

(when the gateway is configured successfully, Destination the value is 0.0.0.0 , if not four zeros means that the gateway is not configured, the gateway address and IP address should be in a network segment)

2,NETSTAT-NR

[[Email protected]]# NETSTAT-NR

Kernel iprouting Table

Destination Gateway genmask Flags MSS Window Irtt Iface

192.168.163.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2

172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 Eth3

0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 Eth3

Third, restart the network services

Service Networkrestart

Modify the NIC namefirst, modify the corresponding configuration file

Vim/etc/udev/rules.d/70-persistent-net.rules

Second, check the network card corresponding to the network card driver

Ethtool–i eth2 (although the corresponding configuration file has been modified, delete the previous eht0 and eth1, and change Eth3 and eth4 accordingly to 0 and 1, but the file does not take effect, so check the network card driver should enter the original network card name, instead of the modified NIC name)

Third, uninstall and reinstall the NIC driver

Rmmod e1000/modprobe–r e1000(uninstall)

Modprobe e1000(installation)

Note: After the successful operation of modifying the NIC name in the previous series, you can enter the modified IP address, and then follow the IP modification method can proceed smoothly. (This is a smooth order and will not cause too many problems, but it can be solved if you understand the principles.)

When you restart the network service, the configuration file is re-read and the contents of the configuration file are added automatically when the corresponding network card is not found.

The configuration file to be consistent with the actual network card, there is no corresponding configuration network card can not exist useless configuration files, or the computer will try to read the file, resulting in an error.

Pingusage of

Command parameters:

-D uses the So_debug function of the Socket .

-F limit detection. Send a large and fast network packet to a machine to see its response.

-n outputs only numeric values.

-Q does not display information for any transmittal packets, only the final result is displayed.

-R ignores normal routingtableand sends packets directly to the remote host. This is usually a matter of looking at the network interface of this computer.

-R records the routing process.

-V shows the execution of the instruction in detail.

number of <p>-c: Stop after sending a specified number of packages.

-I seconds: set interval a few seconds to send a network packet to a machine, the default value is one second to send once.

-I network interface: sends out packets using the specified network interface.

-L Pre-load: Sets the packets that are emitted before the requested information is sent.

-P Template style: Sets the template style that fills the packet.

-S Bytes: Specifies the number of bytes sent , with a preset value of 8 bytes of ICMP header, and a total of 64ICMP bytes of data .

-T Survival value: Sets the size of the live value TTL.


This article is from the "13145479" blog, please be sure to keep this source http://13155479.blog.51cto.com/13145479/1965835

Configuring routers in Linux

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.