Linux Network-related configuration

Source: Internet
Author: User
Tags aliases

Network configuration file

IP, MASK, GW, DNS-related configuration files:/etc/sysconfig/network-scripts/ifcfg-iface

Device: Devices to which this profile applies, determine the device name

HWADDR: MAC address of the corresponding device

Bootproto: The address configuration protocol used when activating this device, commonly used DHCP----dynamic, static---static, none---manually specified, BOOTP

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

onboot: Whether this device is activated at system boot time; recommended Yes

Type: interface types; common Ethernet, Bridge.

UUID: Unique identification of the device

ipaddr: Specify IP Address

NETMASK: Subnet mask equivalent to prefix= digit

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", whether to allow DHCP server to assign a DNS server to direct the information to overwrite the /etc/resolv.conf file

Routing-related configuration files:/etc/sysconfig/network-scripts/route-iface

Note: Requires service network restart to take effect

Two different styles:

(1) TARGET via GW

such as: 10.0.0.0/8 via 172.16.0.1

(2) Define one route per three lines

Address#=target

Netmask#=mask

Gateway#=gw

DNS name Resolution

DNS configuration file; /etc/resolv.conf

Search Localdomain #你的域名

NameServer 192.168.61.1 #DNS

[[email protected] ~]# Ping www

PING www.ghosts2.com (101.200.188.230) bytes of data.

Your domain name is www.ghosts2.com.

Nic Aliases

Useful for the same physical NIC for a virtual host

Ifconfig command:

Ifconfig eth0:0 192.168.1.100/24 up

Ifconfig eth0:0 Down

IP command:

IP addr Add 172.16.1.2/16 dev eth0 label eth0:0

IP addr del 172.16.1.1/16 dev eth0 label eth0:0

IP addr Flush Dev eth0 label eth0:0 Remove NIC Aliases

Alias in effect: Copy network profile CP Ifcfg-eth0 Ifcfg-eth0:1 then vim ifcfg-eth0:1 edit configuration DEVICE name corresponds to eth0:1 NIC alias need to manually configure IP, not automatically generated

Implementing A to B communication in a single-sided route

Route C IP is 192.168.61.140/24 nic eth1

| Routing 192.168.61.0/24

Switch

| |

A host------------------------| |----------------------B Host

A IP is 172.18.253.37/16 eth1 B IP is 192.168.61.150/24 eth1

A Route 172.18.0.0/16 B Route 192.168.0.0/24

Do the following for C

Increase the NIC alias for route C

[[Email protected] ~] #cp ifcfg-eth1 ifcfg-eth1:0

Edit Network Card settings

[[Email protected] ~]#vim ifcfg-eth1:0

name=eth1:0

device=eth1:0

ipaddr=172.18.253.40

Prefix=16

Increase routing configuration

[[Email protected] ~] #ip route add 172.18.0.0/16 Dev eth1:0

Turn on route forwarding for C

[[Email protected] ~] #echo 1>/proc/sys/net/ipv4/ip_forward

Network Interface Configuration-bonding

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

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: Only one slave is activated, and the other slave is activated 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: Transmit all messages on all slave interfaces, providing fault tolerance

Bonding configuration:

Create a configuration file for a bonding device

/etc/sysconfig/network-scripts/ifcfg-bond0

Device=bond0

Bootproto=none manually specifying IP

bonding_opts= "miimon=100 mode=0" specified mode

/etc/sysconfig/network-scripts/ifcfg-eth0

Device=eth0

Bootproto=none

Master=bond0

Slave=yes

Userctl=no

View bond0 status :/proc/net/bonding/bond0

Delete Bond0

(1) ifconfig bond0 down

(2) Rmmod bonding

(3) Modify Ifcfg-eth0 ifcfg-eth1 configuration file to remove Master SLAVE

Implementing eth1 eth0 Binding the same IP address

650) this.width=650; "height=" 402 "title=" msohtmlclipclip_image001 "style=" border-top:0px;border-right:0px; border-bottom:0px;border-left:0px, "alt=" msohtmlclipclip_image001 "src=" http://s3.51cto.com/wyfs02/M02/00/39/ Wkiom1mzfhqqeooaaaflyohgne0128.png "border=" 0 "/>

Modify Host Name

1. Modify the command to take effect

Hostnamectl--static Set-hostname kami777

2. Edit/etc/hosts Add host Name

127.0.0.1 kami777 localhost localhost.localdomain localhost4 localhost4.localdomain4

Kami777 corresponding IP is 127.0.0.1

The host file acts quite like DNS, providing the IP address to the corresponding hostname

The Linux system issues a domain name resolution request to the DNS server to query the/etc/host file and, if there is a corresponding record, use the records in the hosts

Modify the /etc/sysconfig/network in CETOS6

Getent hosts view/etc/hosts content

change centos7 nic name eno16777736 to Eth0

1. Modify the NIC configuration file name

[Email protected] ~]# cd/etc/sysconfig/network-scripts/

[Email protected] ~]# MV ifcfg-eno16777736 Ifcfg-eth0

2. Modify the configuration file name device two items

[Email protected] ~]# vim Ifcfg-eth0

Name=eth0

Device=eth0

3. Modify/etc/sysconfig/grub Add net.ifname=0

grub_cmdline_linux= "Crashkernel=auto net.ifnames=0 rhgb quiet"

4. Regenerate GRUB Configuration Update kernel parameters

[[email protected] ~] #grub2-mkconfig-o/boot/grub2/grub.cfg successfully restarted

Client 1 to Client 2 routing configuration (no routing in the middle of the same network segment)

Known Client 1:

IP is

inet 172.18.251.197 netmask 255.255.0.0 broadcast 172.18.255.255

Routing is configured to

Destination Gateway genmask Flags Metric Ref use Iface

172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 eth0

Client 2:

IP for process

inet addr:192.168.61.139 bcast:192.168.61.255 mask:255.255.255.0

Routing is configured to

Destination Gateway genmask Flags Metric Ref use Iface

192.168.61.0 0.0.0.0 255.255.255.0 U 1 0 0 Eth3

[[Email protected] ~] #ping 172.18.251.197

Connect:network is unreachable

No client 2-to-client 1 routes are pointing, Ping is not through, and the routing table is increased in Client 2

[[email protected] ~] #route Add default GW 192.168.61.1 dev eth3 defaults gateway specify next hop to find IP not in routing table

Destination Gateway genmask Flags Metric Ref use Iface

192.168.61.0 0.0.0.0 255.255.255.0 U 1 0 0 Eth3

0.0.0.0 192.168.61.1 0.0.0.0 U 0 0 0 Eth3

[[Email protected] ~] #ping 172.18.251.197

PING 172.18.251.197 (172.18.251.197) bytes of data.

From 192.168.61.139 icmp_seq=7 Destination Host Unreachable

End 1 No end 2 routing location has to go back, need to increase the routing location at the end 1

[[Email protected] ~] #route Add default GW 172.18.0.1 dev eth0

Destination Gateway genmask Flags Metric Ref use Iface

172.18.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0

0.0.0.0 172.18.0.1 0.0.0.0 U 0 0 0 eth0

End 1 receives and responds and joins the record to the routing table

192.168.61.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0

Linux Network-related 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.