Linux basic network configuration

Source: Internet
Author: User
Tags time 0 nameserver

For the seemingly simple network configuration problems of linux experts, it may not be easy to say why, so it is not surprising that too many beginners remain out of the door,
Here, the old boy teacher spent some time summing up the summary of this document, which is not perfect yet. You are welcome to add and exchange ideas. Thank you!
Directory:
1) configure and modify the host name hostname
2) Nic configuration file description:
3) configure and modify IP addresses
4) configure and modify the gateway
5) configure and modify DNS
6) view ip, gateway, route, and DNS configurations
A. [How to view ip configuration]
B. [view gateway and routing methods]
C. [How to view dns configuration]
7) if the win32 and linux servers cannot connect to the network, what are the troubleshooting methods described separately?
 
##########################
#### 1) configure and modify the Host Name:
##########################
Temporary method:
Hostname oldboy
Log out of the current shell and log on again. This method can only take effect temporarily, and becomes invalid after the system is restarted.
Tip: many people use the hostname to modify the host name. In fact, this is only for the moment. After restarting, it will be restored to the pre-configured host name.
 
Permanent method:
Method 1:
Step 1:
Vi/etc/sysconfig/network
Change HOSTNAME = XX to HOSTNAME = oldboy and save it.
Tip: After modification, the/etc/init. d/network restart or source/etc/sysconfig/network operations will not take effect.
If you want to modify this file, you may need to restart the server.
Question: Here is the current and permanent effective method that comes with the system that directly takes effect, that is, load the hostname and call the command of the configuration file to execute it,
Leave this question to everyone!
 
Step 2:
Then, use the command line to continue the modification: hostname oldboy. After the modification is complete, log out and log on again to make the modification take effect.
Tip: this will ensure the temporary effectiveness, and the restart of the system will also take effect.
 
Method 2:
Another change that takes effect permanently: execute setup-network configuration -- Edit DNS configuration -->
 
DNS configuration
X
X Hostname oldboy _______ x ============> modify here
X Primary DNS 202.106.0.20 ___ x
X Secondary DNS 211.147.6.3 ____ x
X Tertiary DNS ___________ x
X Search _______________ x
Tip: after saving the changes, the changes will take effect immediately and take effect again. From this, we can see that the system still has a temporary and permanent effective method.
 
Note: The above methods may cause the host name corresponding to 127.0.0.1 in/etc/hosts to not be modified. In this case, manually modify the host name, for example:
[Root @ oldboy ~] # Cat/etc/hosts
# Do not remove the following line, or various programs
# That require network functionality will fail.
127.0.0.1 oldboy localhost. localdomain localhost ==========> modify the oldboy
: 1 localhost6.localdomain6 localhost6
10.0.0.190 www.etiantian.org
Tip: If/etc/hosts is not changed, some problems will occur in the future, such as slow sendmail startup and slow ldap service resolution, the slow User Switching of sudo is caused by the inconsistent resolution between the host name and/etc/hosts.
 
Extended: script for restarting host name settings in the system:
[Root @ oldboy ~] # Grep-I hostname/etc/rc. d/rc. sysinit
HOSTNAME = '/bin/hostname'
If [-z "$ HOSTNAME"-o "$ HOSTNAME" = "(none)"]; then
HOSTNAME = localhost
# Set the hostname.
Update_boot_stage RChostname
Action $ "Setting hostname $ {HOSTNAME}:" hostname $ {HOSTNAME }===========> here, the rc is executed after the system restarts. after sysinit, modify the machine name.
# Use the network address to set the hostname of the client. This
If ["$ HOSTNAME" = "localhost"-o "$ HOSTNAME" = "localhost. localdomain"]; then
Hostname $ {HOSTNAME}
Mount-t nfs $ CLIENTSTATE/$ HOSTNAME $ STATE_MOUNT-o rw, nolock
# Reset the hostname.
Action $ "Resetting hostname $ {HOSTNAME}:" hostname $ {HOSTNAME}
[Root @ oldboy ~] # Grep-I hostname/etc/rc. d/init. d/network ============> there is no host name-related information here.
 
################################
#### 2) Nic configuration file description:
################################
 
[Root @ oldboy ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0 = here is the default configuration file for the eth0 Nic Device
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0 ==================== "here is the name of the Network Adapter. The first network adapter is eth0, and the second is eth1...
BOOTPROTO = static ============== "static is a fixed IP address, obtained from non-dynamic DHCP
BROADCAST = 10.0.0.255 =======" here is the BROADCAST address, generally the last address of the network address.
HWADDR = 00: 0C: 29: 0E: 5F: 63 = "here, the mac address must be unique on different machines, pay attention to the configuration of the ECS instance or the NIC.
IPADDR = 10.0.0.161 ==========
NETMASK = 255.255.255.0 ====== "subnet mask/24
NETWORK = 10.0.0.0 ==========
ONBOOT = yes ==========================
GATEWAY = 10.0.0.254 ==========, configure the GATEWAY, or use the command line to add or delete the GATEWAY.
TYPE = Ethernet ====================== TYPE
Tip: The first Nic is a ifcfg-eth0, the second is a ifcfg-eth1...
 
################################
#### 3) configure and modify the IP Address:
################################
How to configure the Server IP address, DNS, and other network configurations:
1) setup-network configuration, and then modify.
2) directly edit or hand-Write the configuration file above.
/Etc/sysconfig/network-scripts/ifcfg-eth0 ====================== Nic Configuration
/Etc/resolv. conf ====================> DNS client Configuration
 
Tip: the above two methods generally need to be restarted or reloaded/etc/init. d/network restart or/etc/init. d/network reload to take effect.
 
##########################
#### 4) configure and modify the gateway gw:
##########################
Method 1: Modify/etc/sysconfig/network
[Root @ oldboy network-scripts] # cat/etc/sysconfig/network
NETWORKING = yes
NETWORKING_IPV6 = no
HOSTNAME = oldboy
GATEWAY = 10.0.0.254 ===" this is the GATEWAY configuration.
Prompt; you need to execute/etc/init. d/network reload to take effect.
 
Method 2: Modifying/etc/sysconfig/network-scripts/ifcfg-eth0
[Root @ oldboy network-scripts] # cat ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0
BOOTPROTO = static
BROADCAST = 10.0.0.255
HWADDR = 00: 0C: 29: 0E: 5F: 63
IPADDR = 10.0.0.161
NETMASK = 255.255.255.0
NETWORK = 10.0.0.0
ONBOOT = yes
GATEWAY = 10.0.0.254 ===" this is to add the GATEWAY configuration. By default, no
Prompt; you need to execute/etc/init. d/network restart or reload to take effect.
 
Note:
1) The Gateway configuration in/etc/sysconfig/network-scripts/ifcfg-eth0 takes precedence over/etc/init. d/network
2) Pay attention to the configuration case. gATEWAY = 10.0.0.254 is not in the lower-case format.
 
Method 3: run the following command to modify the Default Gateway:
[Root @ oldboy network-scripts] # route del default gw 10.0.0.254 = delete it first
[Root @ oldboy network-scripts] # route-n = view command
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
[Root @ oldboy network-scripts] # route add default gw 10.0.0.254 = add default Gateway
[Root @ oldboy network-scripts] # route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0
Note: This modification is temporary and will expire after the NIC is reloaded or started. The solution is to configure it in the configuration file as much as possible,
Put the route add default gw 10.0.0.254 in the rc. local self-starting file or/etc/init. d/network Nic if you need it.
In the script configuration of the restart/reload segment, automatic start or restart of the NIC also takes effect. This is also a bit complicated. Don't do it, okay?
 
##########################
#### 5) modify the host DNS Configuration
##########################
Method 1: setup-network configuration graphical operations
 
Method 2: Modify the path of the host DNS configuration file in/etc/resolv. conf =
[Root @ oldboy network-scripts] # cat/etc/resolv. conf
Nameserver 202.106.0.20
Nameserver 8.8.8.8
Nameserver 211.147.6.3
Tip: This resolv. conf line for each configuration takes effect directly after modification. Note that it is not nameservers,
In addition, this configuration file also has knowledge. You can view it in man resolv. conf.
 
##########################
### 6) view ip address, gateway, route, and DNS Configuration:
##########################
 
[A. How to view ip configuration]
[Root @ oldboy ~] # Ifconfig = "direct command name indicates displaying all Nic IP addresses
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: 1D: 28: D5
Inet addr: 10.0.0.190 Bcast: 10.0.0.255 Mask: 255.255.255.0
Inet6 addr: fe80: 20c: 29ff: fe1d: 28d5/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 4154 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 3107 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 367589 (358.9 KiB) TX bytes: 481210 (469.9 KiB)
Interrupt: 185 Base address: 0x1400
 
Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 36 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 36 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 3744 (3.6 KiB) TX bytes: 3744 (3.6 KiB)
 
[Root @ oldboy ~] # Ifconfig eth0 = show the IP address of the specified Nic
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: 1D: 28: D5
Inet addr: 10.0.0.190 Bcast: 10.0.0.255 Mask: 255.255.255.0
Inet6 addr: fe80: 20c: 29ff: fe1d: 28d5/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 4170 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 3130 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 368687 (360.0 KiB) TX bytes: 484496 (473.1 KiB)
Interrupt: 185 Base address: 0x1400
 
[B. View gateways and routing methods]
[Root @ oldboy network-scripts] # route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0
 
[Root @ oldboy ~] # Netstat-rn = This method can be left empty. Just remember route-n.
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
 
View the man or info or command for linux Command help -- help:
Example: view route usage
Man route and info route or route -- help
The route function is powerful, and students must be familiar with it. The above is only a simple usage.
 
[C. How to view DNS configuration]
[Root @ oldboy ~] # Cat/etc/resolv. conf = "this is a common check method.
Nameserver 202.106.0.20
[Root @ oldboy ~] # Ping g.cn = "this is a common check method. The IP address returned is clearly indicated.
PING g.cn (74.125.71.160) 56 (84) bytes of data.
64 bytes from hx-in-f160.1e100.net (74.125.71.160): icmp_seq = 1 ttl = 49 time = 51.7 MS
 
[Root @ oldboy ~] # Host www.etiantian.org = "is a common check method. If the IP address is returned, it indicates that dns is enabled.
Www.etiantian.org has address 211.100.98.99
 
--- G.cn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0 ms
Rtt min/avg/max/mdev = 51.710/51.710/51.710/0.000 MS
[Root @ oldboy ~] # Dig www.etiantian.org
 
; <> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <> www.etiantian.org
; Global options: printcmd
; Got answer:
;-> HEADER <-opcode: QUERY, status: NOERROR, id: 45736
; Flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
 
; Question section:
; Www.etiantian.org. IN
 
; Answer section:
Www.etiantian.org. 600 in a 211.100.98.99
 
; Query time: 90 msec
; SERVER: 202.106.0.20 #53 (202.106.0.20)
; WHEN: Mon Feb 20 11:50:57 2012
; Msg size rcvd: 51
 
[Root @ oldboy ~] # Nslookup
> Www.etiantian.org
Server: 202.106.0.20
Address: 202.106.0.20 #53
 
Non-authoritative answer:
Name: www.etiantian.org
Address: 211.100.98.99
 
7) if the win32 and linux servers cannot connect to the network, what are the troubleshooting methods described separately?
This question is left to everyone. You can make comments or communicate with me separately.
Tip: basic check ideas:
A. is the physical link unobstructed?
B. Whether the local IP address, route, and DNS settings are up to standard.
C. Test the smoothness of the gateway or router.
D. Test the general situation of ping a public ip address (several external IP addresses should be recorded at ordinary times)
E. Test DNS smoothness. You can ping etiantian.org to check whether the corresponding IP address exists.
Based on the results of each level, if you are a system administrator and have checked all the above problems, you can also test them up and down on the Gateway Routing Server.
Perform step-by-step troubleshooting.
The old boy teacher looks forward to more ideas and troubleshooting methods.
 
From http://oldboy.blog.51cto.com/2561410/784625
 

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.