Linux system basic network configuration old bird essence

  For the seemingly simple network configuration problems of Linux masters, it may not be easy to say why, so it is not surprising that there are still too many beginners wandering outside the door.
Here, the old boy teacher took some time to summarize This document summary is not perfect, and everyone is welcome to add and exchange. thank you all! 20120827 Supplement:
http://oldboy.blog.51cto.com/2561410/974194 In-depth  route command summary
directory:
1) Configure and modify hostname hostname
2) Network card configuration file description:
3) Configure and modify ip address
4) Configure and modify gateway gateway
5) Configure and modify DNS
6) View ip, gateway or routing, DNS configuration
  a.[View ip configuration method]
  b.[View gateway and routing method]
  c.[View dns configuration method]
7) If win32 and linux servers cannot be connected Network, describe the troubleshooting method separately?

################################
1) Configuration modification hostname:
############# #############
Temporary method:
hostname oldboy
exits the current shell and logs in again to take effect. This method can only be modified temporarily and will be invalid after restarting the system.
Tip: Many people use the hostname to modify the hostname. In fact, this is only temporary, and it will be restored to the hostname before the configuration after restarting.

Permanent method:
Method 1:
Step 1:
vi /etc/sysconfig/network
Change the HOSTNAME=XX in it to HOSTNAME=oldboy, and save it.
Tip: After the modification here, the execution of /etc/init.d/network restart or source /etc/sysconfig/network will not take effect
      . If you want to modify this file only, you may need to restart the server.
Digression: There should be a current and permanent method that comes with the system that has a direct effective method, that is, the command to load the configuration file called by hostname and execute it,
leave this problem to everyone!

Step 2:
Then continue to modify through the command line: hostname oldboy. After completion, log out and log in again to take effect
. Tip: This will ensure that it will take effect temporarily and restart the system.

Method 2:
Another method that takes effect immediately and permanently: execute 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 modification and saving, it will take effect in time, and it will also take effect after restarting. From this, it can be seen that the system still has a direct temporary and permanent method to take effect.

Special note: Using the above methods may cause the host name corresponding to 127.0.0.1 in /etc/hosts to not be modified. In this case, it should be modified manually: such as:
[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 oldboy
::1 localhost6.localdomain6 localhost6
10.0.0.190   www.etiantian.org
Tip: If /etc/hosts is not changed, some problems will be encountered in the future, such as slow startup of sendmail, slow parsing of ldap service, slow switching of sudo users, etc. All hostnames and /etc/hosts are not parsing. correspondingly caused.

Extension: Script to set hostname on reboot:
[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} ========== => This is where the machine name is modified after executing rc.sysinit after the system restarts.
        # 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 information related to the hostname here.

####################################
2) Network card configuration file description:
####### ##################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

[root@oldboy ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 =="Here is the default configuration file for the eth0 network card device
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0 === ============"Here is the name of the network card. The first network card is eth0, and the second is eth1...
BOOTPROTO=static============"static For a fixed IP address, non-dynamic DHCP obtains
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 === "The mac address here cannot be repeated for different machines, especially when carving a virtual machine or duplicating network card configuration.
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 setting
ONBOOT=yes ================="The network card will start automatically after booting
GATEWAY=10.0.0.254=========="Gateway The configuration can also be added or deleted through the route on the command line.
TYPE=Ethernet==============" type
hint: the first network card is ifcfg-eth0, the second is ifcfg-eth1...

####################################
3) Configure and modify the ip address:
####### ###########################################################################################################################################################################

EQ _
2) Directly edit or handwrite the above configuration file.
  /etc/sysconfig/network-scripts/ifcfg-eth0 ==============="Network card configuration
  /etc/resolv.conf============== = "DNS client configuration

Tip: The above two methods generally need to restart or reload /etc/init.d/network restart or /etc/init.d/network reload to take effect.

################################
4) Configuration modification 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: Modify /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 increase the configuration of the gateway, There is no prompt by default
; you need to execute /etc/init.d/network restart or reload to take effect.

Special attention:
1) The gateway configuration in /etc/sysconfig/network-scripts/ifcfg-eth0 takes precedence over /etc/init.d/network
2) Pay attention to the capitalization of the configuration, the lowercase format such as gATEWAY=10.0.0.254 is incorrect .

Method 3: Modify the default gateway through the command:
[root@oldboy network-scripts]# route del default gw 10.0.0.254 ==" Delete it first
[root@oldboy network-scripts]# route -n ==" View the 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 Configure it in the configuration file. If there
is a need, put route add default gw 10.0.0.254 into the rc.local self-starting file or the /etc/init.d/network card
restart/reload segment script configuration to realize self-starting or restarting. Starting the network card also takes effect, which is a bit too complicated, let's not do this, okay?

################################
5) Modify the host DNS configuration
############## ############
Method 1: setup--network configuration graphic operation

Method 2: Modify /etc/resolv.conf  ==" the path of the host DNS configuration file here
[root@oldboy network-scripts]# cat /etc/resolv.conf 
nameserver 202.106.0.20
nameserver 8.8.8.8
nameserver 211.147.6.3
Tips: Each configuration line of this resolv.conf will take effect directly after modification. Note that it is not nameservers. In
addition, this configuration file is also knowledgeable. Students can view it with man resolv.conf.

###########################
###6) View ip, gateway or route, DNS configuration:
######### #################

[a. View ip configuration method]
[root@oldboy ~]# ifconfig =="The direct command name means to display the IP of all network cards
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)

[root@oldboy ~]# ifconfig eth0 ==》显示指定网卡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 gateway and routing method]
[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 ==" You can forget this method, 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

Check the linux command help command man or info or command --help:
Example: check the route usage
man route and info route or route --help
route have powerful functions, students should master it proficiently, the above is just a simple usage.

[c. View DNS configuration method]
[root@oldboy ~]# cat /etc/resolv.conf =="This is a common check method
nameserver 202.106.0.20
[root@oldboy ~]# ping g.cn =="This It is a common inspection method, and the ip address is returned.
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  ==" This is a common check method, and the ip address is returned to indicate that dns is connected.
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
[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      A

;; 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, describe the troubleshooting methods respectively?
   I leave this question to you. You can comment or chat with me individually.
   Tip: Basic inspection ideas:
    a. Whether the physical link is unobstructed
    b. Whether the local IP, routing, and DNS settings are up to standard.
    c. Test the smoothness of the gateway or router.
    d. Test the usual situation of pinging the public network IP (usually need to remember several external IPs)
    e. Test the smoothness of the DNS, you can ping etiantian.org to see if the corresponding IP is available.
   Check according to the results of each level. If it is a system administrator, after checking the above problems, you can also test up and down on the gateway routing server.
   Check step by step.
  The old boy teacher is looking forward to more ideas and investigation methods from everyone.

This article is from the " Old Boy Linux Training " blog, http://oldboy.blog.51cto.com/2561410/784625

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324722148&siteId=291194637