Linux Common network Configuration

Source: Internet
Author: User
Tags aliases set time iptables


Nic Name:

The network interface identifies and names the associated udev configuration files:

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

To uninstall the NIC driver:

Modprobe-r e1000

Load NIC driver:

Modprobe e1000

The NIC name is defined in the/etc/udev/rules.d/70-persistent-net.rules file, which defines the details of how the network card is named.

This file is automatically generated when the system is installed.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/D9/wKioL1fNLfvgm5zhAAAuGUd9aas327.png "title=" 11.png "alt=" Wkiol1fnlfvgm5zhaaaugud9aas327.png "/>

In this file, you can modify the name option to change the name of the network card, the modification will need to change the corresponding configuration file, or the NIC will not start,

Edit Network card profile vim/etc/sysconfig/network-scripts/ifcfg-NIC name

Modify the "device=" entry

You can use the Service network Restart command to restart the network service after you modify it

If the configuration file is modified automatically, it is because of the NetworkManager service is running, but the effect of this service is entirely by luck, so the general situation is to turn this service off.

However, use the Service NetworkManager Status command to view the status of services

Service NetworkManager Stop Stop This services

Chkconfig NetworkManager off this service does not start the next time the system starts


Network card configuration File "/etc/sysconfig/network-scripts/ifcfg-eth0" the meaning of the items represented:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/D9/wKioL1fNLh7z23NrAAJI1jdgqFI024.png "title=" 12.png "alt=" Wkiol1fnlh7z23nraaji1jdgqfi024.png "/>




Nic Aliases:

Work often encountered, in multiple network environment to switch back and forth, if only one IP needs to be changed back and forth, so you need a network card to bind multiple IP addresses, so you can avoid manually switching networks back and forth.

Nic Aliases:

First, close the NetworkManager service

Service NetworkManager Stop

Create a configuration file with the file name of the NIC + ": num" as:

The network card file is: Ifcfg-eth0, create the file "Ifcfg-eth0:1", the colon followed by the number, can be arbitrarily specified.


Example: Virtual network card implements one network card multiple addresses


#cd/etc/sysconfig/network-scripts#vim ifcfg-eth0 device= "eth0" bootproto= "DHCP" onboot= "yes" ~ #vim Ifcfg-eth0 : 1 device= "eth0:1" ipaddr=10.1.1.60 prefix=16 gateway=10.1.1.254 dns1=8.8.8.8 onparent=yes

Restart Network Service:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/86/D9/wKioL1fNLnqz4HEJAAAiWfp911U253.png "title=" 13.png "alt=" Wkiol1fnlnqz4hejaaaiwfp911u253.png "/>

To view network card information:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/86/D9/wKioL1fNLq-R_WD7AABqIgYUDXE898.png "title=" 14.png "alt=" Wkiol1fnlq-r_wd7aabqigyudxe898.png "/>


The use of network card aliases should be noted:

Useful for Virtual hosts

To bind multiple IP addresses to a NIC, name the format:

Eth0:1

Eth0:2

Eth0:3

Generate a separate interface profile for each device alias

1. Close NetworkManager Service

2. configuration file naming format ifcfg-ethx:xxx

3. Must use static network

device=eth0:0

ipaddr=10.10.10.10

netmask=255.0.0.0

Onparent=yes

Note: Restart Network Services service Network restart effective

Reference/usr/share/doc/initscripts-*/sysconfig.txt




Network Interface Configuration-bonding

Bonding: is to bind multiple network cards to the same IP address to provide services, can achieve high availability or load balancing. Of course, it is not possible to set the same IP address directly for two NICs. Through the bonding, the virtual one network card provides the connection externally, the physical network card is modified to the same MAC address.


Bonding mode of operation:

Mode 0 (BALANCE-RR)

Rotation (round-robin) strategy: Send packets above and below each slave interface in a sequential order. This mode provides load balancing and fault tolerance capabilities

Mode 1 (active-backup)

Active-Backup (Master) policy: In the binding, only one slave is activated. Other slave are activated when and only if the active slave interface fails. To prevent the switch from confusing, the bound MAC address is visible on only one external port

Mode 3 (broadcast)

Broadcast strategy: All messages are transmitted on all slave interfaces. This mode provides fault-tolerant capability. Bonding configuration



Create a configuration file for a bonding device

#vim/etc/sysconfig/network-scripts/ifcfg-bond0device=bond0bootproto=nonebonding_opts= "miimon=100 mode=0"
#vim/etc/sysconfig/network-scripts/ifcfg-eth0device=eth0bootproto=nonemaster=bond0slave=yesuserctl=no


The Miimon is used for link monitoring. If the miimon=100, then the system every 100MS monitoring link connection status, if one line is not connected to another line

View bond0 Status:/proc/net/bonding/bond

For detailed configuration of bonding, please refer to:

/usr/share/doc/kernel-doc-version/documentation/networking/bonding.txt


Example:

Create Mode 1 (active-backup)

First ensure that the NetworkManager service is in a stopped state

# Service NetworkManager Stop

Create the bonding profile in the/etc/sysconfig/network-scripts directory

# vim ifcfg-bond0device=bond0ipaddr=10.1.252.60prefix=16gateway=10.1.0.1dns1=8.8.8.8bonding_opts= "miimon=100 mode =1 "

Then edit the configuration file for the first NIC

# Vim Ifcfg-eth0device=eth0slave=yesmaster=bond0

To edit the configuration file for the second NIC:

# Vim Ifcfg-eth1device=eth1slave=yesmaster=bond0

Restart Network Service:

# Service Network Restart

Successful execution of the ifconfig command can see the MAC address of two network cards exactly the same, and two network cards share a MAC address

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/D9/wKioL1fNMwyAfxP-AABTZv2ahnA997.png "title=" 15.png "alt=" Wkiol1fnmwyafxp-aabtzv2ahna997.png "/>

View the/proc/net/bonding/bond0 file to see the current working NIC

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/86/D9/wKioL1fNMyyj9IzmAAA9JcRnSBM914.png "title=" 16.png "alt=" Wkiol1fnmyyj9izmaaa9jcrnsbm914.png "/>

Test: Use another machine, ping this server, ping manually cut off the eth0, because the set time is 100ms detection once, so 100ms after eth1 replacement eth0 work, the intermediate handover time is missing a packet

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/DA/wKioL1fNM0-AvZmqAABNX-lbwWc683.png "title=" 17.png "alt=" Wkiol1fnm0-avzmqaabnx-lbwwc683.png "/>

Review the/proc/net/bonding/bond0 file again to discover that eth1 is active.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/DB/wKiom1fNM2_wmAcjAAAvT29Rasg492.png "title=" 18.png "alt=" Wkiom1fnm2_wmacjaaavt29rasg492.png "/>




Cross-network communication:

Cross-network communication: Routing

Routing classifications:

Host routing

Network routing

Default route


Routing Management Commands:

View: Route-n

Add: Route add

Route add [-net|-host] target [netmask Nm] [GWGW] [[Dev] If]

Cases:

Target: 192.168.1.3 Gateway: 172.16.0.1

# route add-host 192.168.1.3 gw172.16.0.1 Dev eth0

Target: 192.168.0.0 Gateway: 172.16.0.1

# route add-net 192.168.0.0 netmask 255.255.255.0 gw172.16.0.1 Dev eth0# route add-net 192.168.0.0/24 gw172.16.0.1 Dev E Th0

Default route, Gateway: 172.16.0.1

# route add-net 0.0.0.0 netmask 0.0.0.0 gw172.16.0.1# route add default gw172.16.0.1

Delete: Route del

Route del [-net|-host] target [GWGW] [netmask Nm] [[Dev] If]

Cases:

Target: 192.168.1.3 Gateway: 172.16.0.1

# route Del-host 192.168.1.3

Target: 192.168.0.0 Gateway: 172.16.0.1

# route del-net 192.168.0.0 netmask 255.255.255.0



Example:

In VMware, two hosts are used as routing devices, respectively, R1,R2. Two additional clients are required for cross-network segment access.

R1: Two ports, respectively:

Eth0:192.168.60.1/24

Eth1:10.10.0.1/8

R2: Two ports, respectively:

Eth0:172.30.0.1/24

Eth1:10.10.0.2/8

Client 1:

192.168.60.60/24

Client 2:

172.30.0.60/16

, you can achieve client 1 and client two mutual access, because R1 and R2 need to interconnect, so one of their ports need to be in the same network segment.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/86/DB/wKiom1fNNlHDTunHAAA9dWCV4_s338.png "title=" 1.PNG " alt= "Wkiom1fnnlhdtunhaaa9dwcv4_s338.png"/>

The steps are as follows:

Set R1:

First off, NetworkManager service

# Service NetworkManager Stop

To open the route transformation:

Change the file/proc/sys/net/ipv4/ip_forword file to 1, in the open state

# echo 1 >/proc/sys/net/ipv4/ip_forword

Set R1 port eth0:

# Vim/etc/sysconfig/network-scripts/ifcfg-eth0 Device=eth0 ipaddr=192.168.60.1 prefix=24

Save exit


Set R1 port eth1:

# vim/etc/sysconfig/network-scripts/ifcfg-eth1 Device=eth1 ipaddr=10.10.0.1 prefix=8

Save exit


Restart Network Service:

# Service Network Restart

To add a route table:

routing table adjacent network segment is automatically generated, only need to add nonadjacent network segments, and set the gateway needs to be set to the next router adjacent interface.

# route add-net 172.30.0.0/16 GW 10.10.0.2 Dev eth1

To empty the firewall list:

# iptables-f

R1 More information:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/DB/wKiom1fNNwuxI6LlAABFH7iW0Iw185.png "style=" float: none; "Title=" R1. PNG "alt=" Wkiom1fnnwuxi6llaabfh7iw0iw185.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/DA/wKioL1fNNwvCNc6-AAAckrzkTRw609.png "style=" float: none; "title=" R1 route table. PNG "alt=" Wkiol1fnnwvcnc6-aaackrzktrw609.png "/>


Set R2:

Steps and Settings R1 moved to, just some parameters are different,

First off, NetworkManager service:

# Service NetworkManager Stop

To open the route transformation:

Change the file/proc/sys/net/ipv4/ip_forword file to 1, in the open state

# echo 1 >/proc/sys/net/ipv4/ip_forword

Set R2 port eth0:

# vim/etc/sysconfig/network-scripts/ifcfg-eth0device=eth0ipaddr=172.30.0.1prefix=16

Save exit

Set R2 port eth1:

# vim/etc/sysconfig/network-scripts/ifcfg-eth1device=eth1ipaddr=10.10.0.2prefix=8

Save exit

Restart Network Service:

# Service Network Restart

To add a route table:

# route add-net 192.168.60.0/24 GW 10.10.0.1 Dev eth1

To empty the firewall list:

# iptables-f

R2 More information:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/DA/wKioL1fNN8mQysmxAABEg6Qh8Dg028.png "style=" float: none; "Title=" R2. PNG "alt=" Wkiol1fnn8mqysmxaabeg6qh8dg028.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/DB/wKiom1fNN8mjYORyAAAcQl5j-fw082.png "style=" float: none; "title=" R2 route table. PNG "alt=" Wkiom1fnn8mjyoryaaacql5j-fw082.png "/>


Client 1:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/DA/wKioL1fNN-rxJ5zrAAAQJQDWD9E410.png "title=" Client 1. PNG "alt=" Wkiol1fnn-rxj5zraaaqjqdwd9e410.png "/>

Client 2:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/DB/wKiom1fNN_fQHAvrAAAVzJA5MAg004.png "title=" Client 2. PNG "alt=" Wkiom1fnn_fqhavraaavzja5mag004.png "/>

Mutual access between client 1 and client 2 is now possible

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/DB/wKiom1fNOA6ycH9yAAAVHPd6mNs435.png "title=" 5.PNG " alt= "Wkiom1fnoa6ych9yaaavhpd6mns435.png"/>

Because, spanning two routes, the TTL is 64-2, which is 62.



This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1846522

Linux Common network Configuration

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.