CentOS Configuration Network (Ethernet) tutorial

Source: Internet
Author: User
Tags get ip centos nameserver firewall

The first thing to do after installing a system is to configure the network.

Modified parameter profiles and instructions for observing results of important startup scripts
IP-related parameters/etc/sysconfig/network-scripts/ifcfg-eth0 Ifconfig (ip/netmask)
/etc/init.d/network Restart Route-n (Gateway)

DNS etc/resolv.conf Dig www.google.com

Host name/etc/sysconfig/network hostname (host name)
/etc/hosts Ping $ (hostname)
Reboot

1. Setting, starting and observation of Ip/netmask/gateway

Set network parameters to modify/etc/sysconfig/network-scripts/ifcfg-eth0, please remember, this ifcfg-eth0 and file DEVICE name set need to be the same, and, in this file all the settings, basically is Bash's variable setting rules (note case)!

The code is as follows Copy Code
[Root@www ~]# Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Device= "eth0" <== network card code, must be Ifcfg-eth0 relative
Hwaddr= "08:00:27:71:85:BD" <== is the network card address, if only one card, you can omit this item
Nm_controlled= "No" <== do not be subject to other software network management!
onboot= "Yes" <== whether this interface is started by default
Bootproto=none <== Get IP way, in fact, only the key words DHCP, manually can enter none
Ipaddr=192.168.1.100 <== is IP.
netmask=255.255.255.0 <== is the subnet mask
gateway=192.168.1.254 <== is a preset route
# The focus is on the above set of items, the bottom of which can be omitted??? br/> network=192.168.1.0 <== is the first IP of the network segment, which can be omitted
broadcast=192.168.1.255 <== is the broadcast address??? Entropy ÷?br/> mtu=1500 <== is the maximum transmission unit set value, if not changed can be omitted


The information above is very well understood! Please note that each variable (in English on the left) should be capitalized! Otherwise, our script will be misjudged! In fact, there are only 8 of the top of the set value, the other network, broadcast, MTU bird brother did not set Oh! As for the description of the parameters, IPAddr, NETMASK, network, broadcast bird here no longer said, to talk about a number of important settings:

    DEVICE: This set of values followed by the device code needs to be the same as the filename (ifcfg-eth0) that the device code is the same line! Otherwise, it may cause some device names to be unable to find trouble.
    Bootproto: What protocol is used when starting this network interface? If the IP is manually given the environment, please enter static or none, if it is automatically obtained IP, please enter DHCP (do not write a typo, because this is the most important keyword!)
    GATEWAY: Represents the "default GATEWAY for the entire host system", so please pay special attention when setting this project. Do not have to repeat the situation happened Oh! When you have Ifcfg-eth0, ifcfg-eth1 .... For multiple files, just set the gateway in one of the files
    Gatewaydev: If you are not using a fixed IP as gateway, you use a network device as the gateway (usually Router There is such a setting, it can also use Gatewaydev to set the communication brake device! But this setup project is rarely used!
    hwaddr: This thing is the card number of the network card! In the case of a single net card, this setting has no function and can be ignored. But if your host has two identical network adapters, the modules used are the same. At this point, your Linux is likely to eth0, eth1 confuse, and cause your network set up trouble. How to solve it? Because the MAC is written directly on the network card, so specify HWADDR to this configuration file, you can solve the problem of the network card corresponding code! It's very convenient! Once the

is set, let's restart the network interface! So you can update the entire network parameters!

The code is as follows Copy Code
[Root@www ~]#/etc/init.d/network Restart
Shutting down interface eth0: [OK] <== first close the interface
Shutting down loopback interface: [OK]
Bringing up loopback interface: [OK] <== Open Interface again
Bringing Up interface eth0: [OK]
# All network interfaces (including LO) for this host are restarted with the gateway, so the network pauses and opens
#实际上也可以用service来重启:
[Root@www ~] # Service Network restart


This is done??? The wall of the unitary Lu blowing ratio 痪 Non-segmental wei Pure??? /p>

The code is as follows Copy Code
# Check A: Of course, to first look at the IP parameters to no, the focus is IP and Netmask!

# Check A: Of course, to first look at the IP parameters to no, the focus is IP and Netmask!
[Root@www ~]# ifconfig eth0
Eth0 Link encap:ethernet hwaddr 08:00:27:71:85:bd
inet addr:192.168.1.100 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::A00:27FF:FE71:85BD/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:655 errors:0 dropped:0 overruns:0 frame:0
TX packets:468 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:61350 (59.9 KiB) TX bytes:68722 (67.1 KiB) # The data that appears on the top of that IP is the correct startup; Pay special attention to inet addr and Mask project
# If there is no success here, you have to go back and see if the configuration file is wrong, and then network restart again!

# Check Two: check to see if your routing settings are correct
[Root@www ~]# Route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.1.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 1002 0 0 eth0
0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth0# Emphasis is on the special font above! The preceding 0.0.0.0 represents the preset route set value!
# Check Three: test to see if there is a successful online with the router!
[Root@www ~]# ping-c 3 192.168.1.254
PING 192.168.1.254 (192.168.1.254) bytes of data.
Bytes from 192.168.1.254:icmp_seq=1 ttl=64 time=2.08 ms
Bytes from 192.168.1.254:icmp_seq=2 ttl=64 time=0.309 ms
Bytes from 192.168.1.254:icmp_seq=3 ttl=64 time=0.216 ms

---192.168.1.254 ping statistics---
Packets transmitted, 3 received, 0% packet loss, time 2004ms
RTT Min/avg/max/mdev = 0.216/0.871/2.088/0.861 ms# attention! There is a TTL is the correct response! If "Destination Host unreachable" appears
# indicates that there is no successful online to your GATEWAY that indicates a problem! Quickly check for any set error.

Note that if the third check fails, you may want to see if your router is turned off. Or is there a problem with your switch/hub, or is your network line wrong, or is your router's firewall set wrong? Remember to fix it! After these three checks have been completed and successful, then your TCP/IP parameters have been set! This means you can use IP Internet! Just can't use the host name to surf the internet. The next step is to set up DNS??

2, DNS server IP settings and observation

This/etc/resolv.conf is very important! He will affect whether you can query the host name and IP correspondence Oh! Usually the following settings are OK!

The code is as follows Copy Code
[Root@www ~]# vim/etc/resolv.conf
NameServer 168.95.1.1 #这个应改为你自己的DNS, hereinafter
NameServer 139.175.10.20

We use the IP of China Telecom and SeedNet DNS Server in the south as the way of setting up! Please note that if you do not know your closest DNS server IP, then direct input nameserver 168.95.1.1 This China Telecom's DNS host can! However, if your company has set up to prevent DNS requirements of the firewall rules, then you have to consult your company's network management unit to inform your DNS IP settings! Then quickly test to see:

The code is as follows Copy Code
# check four: Look at DNS Is it working smoothly? It's a very important test.
[root@www ~]# dig www.google.com
.... (omitted earlier) ....
;; Question section:
;www.google.com.                         in      A

;; ANSWER section:
www.google.com.         428539  IN       cname   www.l.google.com.
www.l.google.com.       122     IN       a       74.125.71.106
.... (omitted in the middle) ....

;; Query time:30 msec
;; server:168.95.1.1#53 (168.95.1.1)   <== The project here is also very important!
;; When:mon June 01:26:50
;; MSG size  rcvd:284


The above output has two key points, one is the problem query is www.google.com a (address) parameter, and from the answer (Answer) inside get the IP parameter we need. The last section of the Server project is very important! You have to see if it's the same DNS server IP that you're setting! Take the above output for example, Brother Bird uses the China Telecom's DNS server, therefore appears the 168.95.1.1 IP address??? br/>
3, the revision of the host name, start and observation

Modify the hostname to change the/etc/sysconfig/network and/etc/hosts these two files, the contents of these two files is simply deadly Oh!

The code is as follows Copy Code
[Root@www ~]# Vim/etc/sysconfig/network
Networking=yes
Hostname=www.centos.vbird

[Root@www ~]# vim/etc/hosts
192.168.1.100 Www.centos.vbird

# Pay special attention to the original contents of this file do not delete! Just add extra data!

After the modification to start smoothly, you have to reboot. Why do we need to reboot? Because the system already has a lot of service to start, these services if need host name, all is to this file to read. And we know that after the profile update, the service has to be restarted. Therefore, has started and has read this file the service, must have to reboot! That's a problem. So the easiest way to do that is to reboot. But before you reboot, you need to do a job, otherwise, your system will take a lot of time to open the opportunity Oh!

The code is as follows Copy Code
[root@www ~]# Hostname
Localhost.localdomain

# or default value, has not been updated successfully! We're going to have to do the moves!

# Check Five: see if your host name has a corresponding IP? If not, the boot process will be very slow!

[root@www ~]# hostname
localhost.localdomain# or default value, not updated successfully! We're going to have to do the moves!

# Check Five: see if your host name has a corresponding IP? If not, the boot process will be very slow!
[root@www ~]# ping-c 2 www.centos.vbird
Ping www.centos.vbird (192.168.1.100) bytes of data.
Bytes FR Om Www.centos.vbird (192.168.1.100): icmp_seq=1 ttl=64 time=0.015 ms
bytes from Www.centos.vbird (192.168.1.100): ICM p_seq=2 ttl=64 time=0.028 MS

---www.centos.vbird ping statistics---
packets transmitted, 2 received, 0% PAC Ket loss, time 1000ms
Rtt min/avg/max/mdev = 0.015/0.021/0.028/0.008 ms# because we have the IP set/etc/hosts the specified Www.centos.vbird,
# That's why we found the correct ip! to the host hostname Only then can reboot Oh! Important and important!


In the information above, there are five steps to check, and each of these five steps must be successful before you can proceed with it. As for the most important point, be sure to reboot (reboot) After you have modified the HOSTNAME inside the/etc/sysconfig/network. But before restarting, be sure to "Ping host name" and get time response!
 
A Linux machine configured with a network can be managed using SSH, and you can go back to your office and soak up a cup of tea and open your computer to manage it.

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.