Linux network parameter settings _ CentOS6.2

Source: Internet
Author: User

Linux network parameter settings _ CentOS6.2
 
 
With the passage of time, Red Hat launched RHEL6.2, followed by CentOS and exited CentOS6.2. Vendors in the new system have added a large number of virtualization and cloud computing elements, and there have been many changes to the details. Here we only provide a detailed description of the network parameters in the new system.
 
Network Parameters in Linux generally include the following:
 
IP address
 
Subnet Mask
 
Gateway
 
DNS Server
 
Host Name
 
In Linux, the methods for modifying these parameters are usually commands and files. The command setting can take effect immediately, but will expire after restart. It will take effect permanently through file modification, but will not take effect immediately.
 
First, let's look at the command method:
 
Ifconfig: View and set IP addresses and subnet masks
 
Hostname: View and set the Host Name
 
Route: View and set route information (default gateway, etc)
 
Modify by file:
 
/Etc/sysconfig/network-scripts/ifcfg-device name (typically ifcfg-eth0)
 
/Etc/sysconfig/network
 
/Etc/resolv. conf file: sets the DNS server
 
These methods can be implemented in systems 5.0 and 6.0 at the same time. However, ifconfig and route are old commands and replaced by ip commands, which are described in the official documentation after System 6.0.
 
 
 
Let's take a look at the usage of old commands:
 
**************************************** *********************************
 
Ifconfig interface option | Address
 
# Ifconfig eth0 up enable eth0 Nic
 
# Ifconfig eth0 down disable eth0 Nic
 
# Ifconfig eth0-arp disable eth0 Nic arp Protocol
 
# Ifconfig eth0 promisc enable the Mixed Mode of eth0 Nic
 
# Ifconfig eth0 mtu 1400 set the maximum transmission unit of the eth0 Nic to 1400
 
# Ifconfig eth0 192.168.0.2/24 set the IP address of the eth0 Nic
 
# Ifconfig eth0 192.168.0.2 netmask 255.255.255.0 functions are the same as above
 
**************************************** *********************************
 
Host Name:
 
# Hostname view Host Name
 
# Hostname jacob.com set the host name to jacob.com
 
**************************************** *********************************
 
Gateway settings:
 
Route add [-net |-host] target [netmask] gw
 
Route del [-net |-host] target [netmask] gw
 
# Route add-net 192.168.3.0/24 gw 192.168.0.254 set the gateway to 192.168.0.254 in the 192.168.3.0 CIDR Block
 
# Route add-net 192.168.3.0 netmask 255.255.255.0 gw 192.168.0.254 functions the same as above
 
# Route add-host 192.168.4.4 gw 192.168.0.254 set the gateway to 192.168.4.4 host to 192.168.0.254
 
# Route del-net 192.168.3.0/24 Delete the gateway information of the 192.168.3.0 network segment
 
# Route del-host 192.168.4.4 Delete the gateway information of the host 192.168.4.4
 
# Route add default gw 192.168.0.254 set the default gateway to 192.168.0.254
 
# Route del default gw 192.168.0.254 Delete the default gateway as 192.168.0.254
 
**************************************** *********************************
 
The IP address command is no longer recommended on the official website. Let's take a look at its usage:
 
Ip [Option] operation object {link | addr | route ...}
 
# Ip link show Displays Network Interface Information
 
# Enable Nic for ip link set eth0 up
 
# Ip link set eth0 down disable Nic
 
# Ip link set eth0 promisc on enable mixed Nic Mode
 
# Ip link set eth0 promisc off disable mixed Nic Mode
 
# Ip link set eth0 txqueuelen 1200 set the length of the NIC queue
 
# Ip link set eth0 mtu 1400 sets the maximum transmission unit of the NIC
 
 
 
# Ip addr show Nic IP address information
 
# Ip addr add 192.168.0.1/24 dev eth0 set eth0 Nic ip address 192.168.0.1
 
# Ip addr del 192.168.0.1/24 dev eth0 Delete eth0 Nic ip Address
 
 
 
# View route information in ip route list
 
# Ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 set the gateway of the 192.168.4.0 network segment to 192.168.0.254, and the data goes through the eth0 Interface
 
# Ip route add default via 192.168.0.254 dev eth0 set the default gateway to 192.168.0.254
 
# Ip route del 192.168.4.0/24 Delete the gateway of the 192.168.4.0 network segment
 
# Ip route del default delete default route
 
**************************************** *********************************
 
Next let's take a look at modifying network parameters through a file: (CentOS6.2 system as an example)
 
# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
 
DEVICE = "eth0" DEVICE name
 
Whether the NM_CONTROLLED = "yes" device is managed by NetworkManager
 
ONBOOT = "no" start or not
 
HWADDR = 00: 0C: 29: E8: 21: A2 hardware address (MAC address)
 
TYPE = Ethernet TYPE
 
BOOTPROTO = none startup Protocol {none | dhcp}
 
IPADDR = 192.168.0.1 IP Address
 
PREFIX = 24 Subnet Mask
 
GATEWAY = 192.168.0.254 Default GATEWAY
 
DNS1 = 202.106.0.20 primary DNS
 
DOMAIN = 202.106.46.151 secondary DNS
 
UUID = 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 device UUID No.
 
**************************************** *********************************
 
# Cat/etc/sysconfig/network
 
HOSTNAME = jacob.com Host Name
 
**************************************** *********************************
 
Note: In the 5.0 era DNS server is written in the/etc/resolv. conf file, but in the 6.0 era DNS is written in the/etc/sysconfig/network-scripts/ifcfg-eth0 file.
 
 
 
Network exclusion ideas:
 
Check the configuration file for errors (writing and syntax errors)
 
Check whether the local network protocol is correct: # ping-c 2 127.0.0.1
 
Check whether the local Nic link is correct: # ping-c 2 192.168.0.1 (local IP address)
 
Check whether the gateway is correct: # ping-c 2 192.168.0.254 (gateway IP address)
 
Check external connectivity: # ping-c 2 www.google.com.hk
 
Check hardware
 
 
This article is from the "ding Adventure" blog

Related Article

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.