Basic network configuration of Linux system Veteran's essence

Source: Internet
Author: User
Tags nameserver

For the Linux master seemingly simple network configuration problem, perhaps to say why is not easy, so there are still too many beginners wandering outside the door is not strange,
Here, the old boy teacher spent some time summing up this document summary, but also not perfect, welcome to add, Exchange. Thank you! 20120827 Supplement:
http://oldboy.blog.51cto.com/2561410/974194 Brief summary of the route command in layman
Directory:
1) Configure the host name to be modified hostname
2) network card configuration file Description:
3) Configure the IP address to be modified
4) configuration Modify Gateway Gateways
5) Configure modify DNS
6) View IP, gateway or routing, DNS configuration
a.[view IP Configuration method]
B.[viewing gateways and routing methods]
c.[view DNS Configuration method]
7) If the Win32 and Linux servers are unable to connect to the network, describe the troubleshooting method separately?

##########################
# # # #1) configuration to modify the host name:
##########################
Temporary method:
Hostname Oldboy
Exit the current shell and log in again to take effect. This method can only be modified in a temporary way and fails after the system is re-established.
Tip: Many people use the hostname hostname to modify, in fact, this is only temporary, restart will be restored to the pre-configuration host name.

Permanent method:
Law One:
Step 1:
Vi/etc/sysconfig/network
Change the hostname=xx inside to Hostname=oldboy, then save.
Tip: After this change, the implementation of/etc/init.d/network restart or source/etc/sysconfig/network and other practices are not effective
If you want to modify this file single, you may need to restart the server.
Digression: Here should be a direct effective method of the system comes with the current and permanent effective method, that is, loading under the hostname call configuration file under the command execution is good,
Leave this problem to everyone!

Step 2:
Then continue to modify through the command line: hostname Oldboy, after the completion of exit re-login is effective
Tip: This will guarantee the temporary effect, and the system system will be in effect again.

Law II:
Additional modification for immediate and permanent effect: Perform setup-network configuration--Edit DNS configuration-->

DNS configuration                   
 x                                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  
Hint: Here after the save will be in time to take effect, re-start also effective, from this can be seen, the system still has a direct temporary permanent effective method.

Special note: The use of the above method may cause the/etc/hosts in the 127.0.0.1 corresponding hostname unmodified, at this time, should be manually modified:
[Email protected] ~]# cat/etc/hosts
# don't remove the following line, or various programs
# that require network functionality would fail.
127.0.0.1 Oldboy localhost.localdomain localhost ===========> modify the Oldboy here
:: 1 localhost6.localdomain6 Localhost6
10.0.0.190 www.etiantian.org
Hint: If/etc/hosts does not change, later will encounter some problems, such as SendMail start slowly, LDAP Service parsing is slow, sudo user slow and so on is the hostname and/etc/hosts in the resolution does not correspond to cause.

Extensions: Scripts for restarting the system settings hostname:
[Email protected] ~]# 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 is where the machine name is modified after the system restarts and after the Rc.sysinit is executed.
# 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}
[[email protected] ~]# grep-i hostname/etc/rc.d/init.d/network ===========> There is no information associated with the host name.

################################
# # # #2) network card configuration file Description:
################################

[[email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0 = = "This is the default profile for the ETH0 network card device
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
Device=eth0 ================ "Here is the network card name the first NIC is Eth0, the second block is eth1 ...
bootproto=static============ Static is a fixed IP address, non-dynamic DHCP gets
broadcast=10.0.0.255 ======= "Here is the broadcast address, which is generally the last address of the network address.
Hwaddr=00:0c:29:0e:5f:63 = = = MAC address here, different machines can not be duplicated, especially when the virtual machine or replication network card configuration should be noted.
ipaddr=10.0.0.161 ========== "Here is the IP address
netmask=255.255.255.0======= subnet mask/24
network=10.0.0.0    ========= "network segment settings
Onboot=yes =================" boot network card self-booting
gateway=10.0.0.254========== "Gateway configuration, You can also add deletes from the command line via the route.
type=ethernet=============== type
Hint: The first NIC is Ifcfg-eth0, the second block is ifcfg-eth1 ...

################################
# # # #3) configuration Modify IP address:
################################
How to configure network configuration such as server IP and DNS:
1) setup-network configuration, and then modify.
2) directly edit or handwriting the above configuration file.
/etc/sysconfig/network-scripts/ifcfg-eth0 =============== "NIC configuration
/etc/resolv.conf=============== the configuration of the DNS client

Tip: The above two methods typically require a restart or reload/etc/init.d/network restart or/etc/init.d/network reload to take effect.

##########################
# # # #4) configuration Modify Gateway GW:
##########################
Law One: Modify/etc/sysconfig/network
[Email protected] network-scripts]# cat/etc/sysconfig/network
Networking=yes
Networking_ipv6=no
Hostname=oldboy
gateway=10.0.0.254 = = "This is the configuration of the gateway
/etc/init.d/network Reload is required to take effect.

Law II: Modify/etc/sysconfig/network-scripts/ifcfg-eth0
[email protected] 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 increase the configuration of the gateway, the default does not
/etc/init.d/network Restart or reload are required to take effect.

Special attention:
1) The gateway configuration in/etc/sysconfig/network-scripts/ifcfg-eth0 takes precedence over/etc/init.d/network
2) Note the case of the configuration, gateway=10.0.0.254 such lowercase format is not correct.

Method Three: Modify the default gateway by command:
[[email protected] network-scripts]# route del default GW 10.0.0.254 = = "First delete
[[email protected] 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
[Email protected] network-scripts]# route add default GW 10.0.0.254 = =
[Email protected] 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 temporarily modified, after reloading or starting the network card will be invalidated, the solution is to try to configure in the configuration file,
There is a need to put the route add default GW 10.0.0.254 into the rc.local self-boot file or/etc/init.d/network NIC
Restart/reload section Script configuration in the implementation of the start-up or restart the network card is also in effect, which is a bit too complicated, let's not do it, okay?

##########################
# # # #5) Modify host DNS configuration
##########################
Law One: setup--Network configuration graphics operations

Law II: modify/etc/resolv.conf = = "Here The path of the host DNS configuration file
[Email protected] network-scripts]# cat/etc/resolv.conf
NameServer 202.106.0.20
NameServer 8.8.8.8
NameServer 211.147.6.3
Hint: Each configuration line this resolv.conf changes directly after the effect, note, not nameservers,
In addition, this configuration file is also knowledgeable, the students can be man resolv.conf view.

##########################
# # #6) View IP, gateway or routing, DNS configuration:
##########################

[A. View IP configuration Method]
[[email protected] ~]# Ifconfig = = "Direct command name indicates all network card IP
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 txqueuelen: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)

[[email protected] ~]# ifconfig eth0 = = "Display specified network card IP
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 txqueuelen:1000
RX bytes:368687 (360.0 KiB) TX bytes:484496 (473.1 KiB)
interrupt:185 Base address:0x1400

[B. View gateways and Routing methods]
[Email protected] 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

[[email protected] ~]# Netstat-rn = = "This method can not remember, remember route-n can."
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 commands for the Linux command help man or info or command--help:
Example: View route usage
Man route and Info route or Route--help
The route is powerful, the students must master, above is only a simple usage.

[C. View DNS configuration Method]
[[email protected] ~]# cat/etc/resolv.conf = = "This is a common method of checking
NameServer 202.106.0.20
[[email protected] ~]# ping g.cn = = "This is a common check method, the return IP address of the description pass.
PING g.cn (74.125.71.160) bytes of data.
Bytes from hx-in-f160.1e100.net (74.125.71.160): icmp_seq=1 ttl=49 time=51.7 ms

[[Email protected] ~]# host www.etiantian.org = = "This is a common check method that returns the IP address that explains the DNS pass.
Www.etiantian.org has address 211.100.98.99

---g.cn ping statistics---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
RTT Min/avg/max/mdev = 51.710/51.710/51.710/0.000 ms
[Email protected] ~]# 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 A

;; ANSWER section:
www.etiantian.org. 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

[email protected] ~]# 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

Basic network configuration of Linux system Veteran's essence

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.