Network configuration commands in Linux

Source: Internet
Author: User

Network configuration commands in Linux

The network structure in Linux is very complex, but the basic user space network configuration is not very difficult. If your Linux system still does not have a network or the connection to the network is faulty, configure it together or check the problem step by step. Of course, my Linux version is centos6.5, with no desktop and full-terminal commands.

--------------------------------------------------------------- Configure the Intranet ------------------------------------------------------------------------------

Step 1: view the current network information. Run the command ifconfig to display all the network card devices in your current system, and the virtual network card or layer-2 bridge. In windows, the command for viewing the NIC device is ipconfig. For details, you can set the parameter "all" and the command "ipconfig/all. Result

If the ifconfig command cannot be found after the instance is started, your network may be normal. A Brief Introduction to the above results, there are two NICs: eth0 and lo; eth0 is set by me, generally, each Linux system has an eth0 block (some are eth1 or eth2). The lo Nic is a block loopback network card, that is, an internal loopback query, you can check whether the hardware of your network card is faulty (you can ping yourself). Each operating system of this device has a problem. But some may not exist.

Step 2: Do not be sad if the result is not displayed in step 1. Run the command ifconfig-a to view all existing Nic devices, including those that do not exist. You cannot automatically enable your Nic because some settings are incorrect or you cannot read your network settings when starting the instance. At this time, you have to manually get up.

If ifconfig-a finds that some devices are not available, you can manually connect to the network. Assume that eth0 is not automatically started, run the command ifconfig eth0 up (disable the NIC command ifconfig eth0 down) if nothing is printed after the command is executed, it indicates that the command is successfully executed (this is a low profile in Linux: The command is successfully executed and nothing is displayed, if it fails, the error message may be flushed.) then run the first command: ifconfig. If the result shows the eth0 information, it indicates that the network adapter has started to work, the network is okay. Of course, this is only temporary. There are two reasons for not automatically starting up: first, when the system is started, there is a problem reading the network configuration script. You can view the startup log; second, there is a problem with network configuration. You can check the network configuration in the next few steps;

Of course, if a problem occurs when the system starts the read script, it may be complicated. I also showed up once at the time. I couldn't read my configuration script when the system was started, and later I found that I disabled the physical Nic device. I will share it later. If no reason is found, it doesn't matter. Use a simple method: Write the ifconfig eth0 up command to the startup script. Run the following command: echo 'ifconfig eth0 up'>/etc/rc. local (I remember to read rc. local, you can see it should be rc. local) append the command to the startup script. Each time you start the instance, the instance is automatically started.

Step 3: This is the key to network configuration. Go to the NIC Directory: cd/etc/sysconfig/network-scripts, you can see a lot of network-related devices; there are two files ifcfg-eth0 and ifcfg-lo, the eth0 and lo Nic devices corresponding to ifconfig. Go to the ifcfg-eth0 File

 

DEVICE = eth0 // This is the name of the network card TYPE = Ethernet // network card type onboot = yes // whether the BOOTPROTO = static // static indicates a fixed IP address as the boot starts, dhcp indicates randomly obtaining ipIPADDR = 192.168.10.150 // manually set the fixed IP address NETMASK = 255.255.255.0 // mask address, that is, mask GATEWAY = 192.168.10.1 // GATEWAY address
You can configure the NIC as needed. The above is my basic configuration and some irrelevant (such as uuid and mac address) are deleted. Set the network to restart: server network restart and ping the Intranet to see if the network is accessible (arp-a can be used to check which hosts are currently open ). If yes, you will probably specify how to set the NIC information. Here, if you want to use eth1, you can copy eth0 and change it to eth1, provided that you have a physical network card and a virtual network card. Now that the internal network is connected, configure the internet.
Configure Internet -------------------------------------------------------------------------------

 

Step 4. If the Intranet is okay, check the internet configuration (you must not skip the Intranet configuration to directly configure the Internet ). First, check whether the Internet and the Internet are accessible. ping Baidu: ping www.baidu.com directly. If yes, the line ends. If the connection fails, the host cannot be identified. Configure the following script. First, you need to configure the DNS and directly enter the file vim/etc/resolv. conf to add two lines of scripts.

 

Nameserver 192.168.10.1 // use a gateway for DNSnameserver 8.8.8.8 // use the DNS provided by Google for free
Step 5. If DNS has been configured in the previous step, you can ping Baidu first to see if it can be reached. If you cannot access the route, you can view the route settings. The concept of routing is a simple one: control the route rules for data packets to arrive outside. Run the following command: rounte-n to view the route table.

 

We can see that there is a default Gateway in the "192.168.10.1" column in the Gateway field. When the data packet cannot be found, it will be lost to the Gateway. The other end of the router is connected to the public network, so if the default Nic is configured, it can communicate with the outside world. If no default gateway exists, manually add a default gateway: route add default gw 192.168.10.1, restart the network, and try again to communicate with the outside world.

If your Linux is not a virtual machine, the network can basically work after these steps are configured. However, if you are using a Linux system installed in a virtual machine, it is still complicated to configure the network.

----------------------------------------------------------------------- Virtual machine configuration Network quota ------------------------------------------------------------------------------------------------

The network configuration steps for virtual machines are roughly the same as those above. The only difference is the exchange with the host machine. If the network cannot be configured in the preceding steps, the network connection to the host machine may be faulty.

First, check the settings in the virtual machine, find the network, and then see how to connect to the network in the virtual machine, you can check the data by yourself for the following features: Bridging, NAT, and HOST-ONLY. Check the network under the host and check whether the network in the virtual machine is forbidden (you can also see it when you change the adapter). I am a VirtualBox virtual machine, there is a VirtualBox network in the host machine.

We can see three networks, VirtualBox networks, wireless networks, and connected networks, you can also use win + r ==> cmd ==> ipconfig/all to view the status of each Nic.

Note: Do not install VirtualBox and VMware on the same host at the same time. When VirtualBox is installed, the network settings of VMware will be changed, therefore, you must reset the network after installing VirtualBox. The other one is not to refresh the mac address of the VM. When you refresh it, it indicates that a new virtual network card is generated. The previous network card is deleted and the network will not start at the beginning, in addition, your Nic name may change, such as eth1 or eth2. At this time can delete two files (A time to forget which file seems to be: xxx-7 xxxx-9, will remind you that the two files can not be read, next time remember to make up)

So far, there have been so many ideas, which is also a conventional network configuration method. If you encounter other problems later, make up the problem. Thank you !! (If you have any network configuration problems or solutions, please let me know. Thank you !!)

Supplement 1: If the/etc/resolv. conf file is restored every time the network is restarted. Disable NetworkManager, cd/etc/init. d, and run the command: service NetworkManager stop in the directory.

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.