CentOS Learning Notes-configuring networks

Source: Internet
Author: User
Tags nameserver

Configuring the Network (Ethernet)

The first thing to do after installing a system is to configure the network. (The following is a list of Linux private dishes from bird brother----Server Erection chapter fourth, connected to the Internet)

Modified parameters Configuration files and Important startup scripts Instructions for observing the results
IP-related parameters

/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/init.d/network restart

Ifconfig (Ip/netmask)
Route-n (Gateway)

Dns

/etc/resolv.conf

Dig www.google.com

Host Name

/etc/sysconfig/network
/etc/hosts

Hostname (host name)
Ping $ (hostname)
Reboot

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

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

[[Email protected] ~]#Vim/etc/sysconfig/network-scripts/ifcfg-eth0Device="eth0"<== network card Code, must be ifcfg-eth0 relative Hwaddr="08:00:27:71:85:BD"<==is the network card address, if there is only one card, you can omit this item nm_controlled="No"<==do not be subject to the network management of other software! Onboot="Yes"<==whether to start this interface by default Bootproto=none <==the way to get the IP, in fact, the keyword only DHCP, manually can input noneipaddr=192.168.1.100 <==It 's IP, netmask.=255.255.255.0 <==is the subnet mask gateway=192.168.1.254 <==is the default route#The focus is on the above set items, the bottom can be omitted! network=192.168.1.0 <==is the first IP of the network segment, which can be omitted broadcast=192.168.1.255 <==It's the broadcast address, you can omit the MTU.=1500 <== is the maximum transmission unit set value, if not changed can be omitted

The above information is very well understood! Please note that each variable (English on the left) should be capitalized! Otherwise, our script will be misjudged! In fact, the bird brother's set value only the top 8, the other NETWORK, broadcast, MTU bird Brother has not set Oh! As for the description of the parameters, IPAddr, NETMASK, NETWORK, broadcast bird brother here will not say more, to talk about is a few important set values:

    • Device: This setting value is followed by the unit code needs to be the same as the file name (ifcfg-eth0) that device code! Doing so may cause some device names not to be found.
    • Bootproto: What protocol is used to start the network interface? If it is a manual IP 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 up this project! Do not have to repeat the situation to happen Oh! That is when you have Ifcfg-eth0, ifcfg-eth1 ... Multiple files, just set up GATEWAY in one of the files
    • Gatewaydev: If you do not use a fixed IP as the gateway, but instead use a network device as the gateway (usually Router most often), you can also use the Gatewaydev to set the communication gate device! However, this set-up project is seldom used!
    • HWADDR: This thing is the card number of the network card! In the case of only one net card, this setting value has no function, can ignore him. But if you have two identical NICs on your console, the modules used are the same. At this point, your Linux is likely to confuse eth0, eth1, and cause your network settings to be confused. 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 network card corresponding code problem! Very convenient!

Once setup is complete, let's restart the network interface now! This will update the entire network parameters!
[[Email protected] ~] # /etc/init.d/network Restart Shutting down interface eth0:         [OK]  <== first close the interface shutting down loopback interface:     [OK]bringing up LOOPB Ack interface:       [OK]  <= = Re-open interface Bringing up interface eth0:           [OK]#  All network interfaces (including LO) for this host are restarted with the communication gate, so the network will stall and open #  Service Network Restart

So it's done, and then of course it's a look!

# Check One: Of course, to first look at the IP parameters to no, the focus is IP and Netmask!

[[Email protected] ~] # ifconfig eth0eth0      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/ scope:link up          broadcast RUNNING multicast  MTU:  metric:1          RX packets: 655 errors:0 dropped:0 overruns:0 frame:0          TX packets:468 errors:0 dropped:0 overruns:0 carrier:0< c18>          Collisions:0 txqueuelen:1000          RX bytes:61350 (59.9 KiB)  TX bytes:68722 (67.1 KiB)

# There is data on the top of that IP is the correct boot; Pay special attention to inet addr and Mask Item # here if not successful, you have to go back to see if the configuration file has errors, and then re-network restart! # Check Two: Check that your routing is set correctly

 
 [[email protected] ~]#   route-n  kernel IP routing tabledestination Gateway genmask Flags Metric Re F 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 Eth00.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth0#   focus on the special font above! The previous 0.0.0.0 represents the set value of the preset route!  
# Check three: test to see if it can be successful online with the router!
[[Email protected] ~] # 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 Msto bytes from 192.168.1.254:icmp_seq=2 ttl=64 time=0.  309 msbytes from 192.168.1.254:icmp_seq=3 ttl=64 time=0.216 ms---192.168.1.254 ping statistics---3 Packets transmitted, 3 received, 0% packet loss, time 2004msrtt min/avg/max/mdev = 0.216/0.871/2.088/0.861 ms

# Watch out! TTL is the correct response! If the "Destination Host unreachable" # indicates that there is no successful online to your GATEWAY that indicates a problem! Check that there are no set errors.

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 cable wrong, or is your router's firewall set up incorrectly? Remember to solve it! After these three checks are done and successful, your TCP/IP parameter setting is complete! This means you can use IP to surf the internet! Just can't use the hostname to surf the internet. The next step is to set up DNS!

2. IP setting and observation of DNS server


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

[[Email protected] ~] # vim/etc/resolv.confnameserver 168.95.1.1  #这个应改为你自己的DNS, the  same as 139.175.10.20

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

 # Check Four: see if DNS works well? Very important Test Oh! 
 [[email protected] ~]#   dig www.google.com   .... (omitted before) ....;                        QUESTION section:;www.google.com.  in   A;         ANSWER SECTION:www.google.com.  428539 in   CNAME www.l.google.com.www.l.go ogle.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 Jul 01:26:50 2011;; MSG SIZE RCVD:  284 

The above output has two key points, one is the www.google.com's A (Address) parameter for the problem query, and the IP parameters we need are obtained from the answer (Answer). The last section of the Server project is very important! You have to see if the DNS server IP is the same as your settings! With the above output as an example, Brother Bird uses Chunghwa Telecom's DNS server, so the IP address of 168.95.1.1 appears.

3, the host name modification, start and observe


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

[[Email protected] ~] # vim/etc/sysconfig/network networking=yeshostname=www.centos.vbird[root@www ~]#  vim/etc/hosts 192.168.1.100    Www.centos.vbird
# Special attention, the original content of this file do not delete! Just add the extra data!

After the modification is completed, it is necessary to restart. Why does it need to be restarted? Because the system already has a lot of service start up, these services if need host name, is to this file to read. And we know that after the configuration file update, the service has to be restarted. Therefore, have started and have read this file service, you have to restart Ah! So the simplest way to do that is to restart. But you'll need to do a lot of work before you reboot, otherwise your system will take a long time to open!

 
 [[email protected] ~]#   hostname  Localhost.localdomain 
# is still the default value and has not been updated successfully! We've got to do the bottom move! # Check Five: see if your host name has a corresponding IP? If not, the boot process will be slow!
 [[email protected] ~]#   Ping-c 2 Www.centos.vbird  PING Www.centos.vbird (192.168.1.100) (84 Bytes from Www.centos.vbird (192.168.1.100): icmp_seq=1 ttl=64 time=0.015 MS  64 Bytes from Www.centos.vbird (192.168.1.100): icmp_seq=2 ttl=64 time=0.028 MS --- Www.centos.vbird Ping Statistics---2 packets transmitted, 2 received, 0% packet loss, time 1 000msrtt min /avg/max/mdev = 0.015/0.021/0.028/0.008 Ms 
# because we have set the IP of the/etc/hosts specified Www.centos.vbird, # so I find it. Correct ip! for host hostname Only then can reboot Oh! Important Important!

In the above information, there are five steps to check the content, the five steps of each step must be successful before you can continue to deal with it! As for the most important point, be sure to restart (reboot) after you have modified the HOSTNAME inside the/etc/sysconfig/network. But before restarting, be sure to "Ping the host name" and get a response from time!

Network-configured Linux machines 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.

CentOS Learning Notes-configuring networks

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.