Network configuration commands under Linux

  
        

The network structure under Linux is very complicated, but the basic user space network configuration is still not very difficult. If your Linux still doesn't have a network or if you have problems connecting to the network, then follow the configuration or step by step to see what's wrong. Of course, my Linux is centos6.5 version, there is no desktop, full terminal command operation.

-------------------------------------------- -----------------Configure intranet ------------------------------ ------------------------------------------------

Step 1, view the current network information, use the command: ifconfig This command will display all the network card device information in your current system, virtual network card or Layer 2 bridge will be displayed. The command to view the NIC device in windows is: ipconfig, the detailed information can be parameter all, the command is: ipconfig/all. The result is as follows:


If you find it after booting with the ifconfig command and the above result is not found, then your network is likely to be normal. Briefly introduce the contents of the above results, first there are two network cards: eth0 and lo; eth0 is set by me, generally each Linux system will have block eth0 (some are eth1 or eth2, etc.); lo NIC is block loopback The network card is the internal loopback query. It can be used to check whether there is a problem with the network card hardware (self ping itself). This device is available for every operating system. But some may not be up.

The second step, if you do not see the results in the first step, then don't be sad, you can use the command: ifconfig -a to view all existing network card devices, including not. Because some settings have problems or you can't read your network settings at boot time, you can't help your NIC automatically. At this time, you have to manually get up.

If ifconfig -a finds something that doesn't get up, then you can do it manually, and the network should be fine. Now suppose that eth0 is not automatically raised, then use the command: ifconfig eth0 up (relative command to close the NIC command: ifconfig eth0 down) If the command is not printed after executing the command, it means that the command is executed successfully (this is a low-key of Linux: command execution) Success does not show anything. If it is not successful, then the error message may be swiped.) Then execute the first command: ifconfig If the result shows eth0 information, then the network card has started working, the network is fine. . Of course, this is only temporary. As for why it doesn't come up automatically, there are two reasons: First, the system configuration script reads the problem when the system starts, this can check the startup log; second, the network configuration step itself, this You can see the network configuration in the next few steps;

Of course, if the system starts to read the script, then this may be more complicated. I also appeared once at the time. I couldn't read my configuration script when I started the system. Later I discovered that I turned off the physical network card device. This will be shared later. If you can't find a reason, it doesn't matter, use a simple method: write the ifconfig eth0 up command to the startup script. Execute the following command: echo 'ifconfig eth0 up' >> /etc/rc.local (I remember to read rc.local, you can see that it should be rc.local) Append this command to the startup script. . It will start automatically every time you turn it on.

The third step, this is the key to network configuration. Enter the directory where the NIC is located: cd /etc/sysconfig/network-scripts, you can view a lot of network-related devices; there are two files, ifcfg-eth0 and ifcfg-lo, which are eth0 and lo NIC devices corresponding to ifconfig. . Enter the ifcfg-eth0 file


DEVICE=eth0 //This is the name of the network card TYPE=Ethernet //NIC type ONBOOT=yes //Whether it starts with boot BOOTPROTO=static //static means fixed ip address, dhcp means random acquisition ipIPADDR=192.168.10.150 //manually set fixed ip address NETMASK=255.255.255.0 //mask address, is mask GATEWAY=192.168.10.1 //gateway address can be based on My own needs to configure the network card, the above is my basic configuration, remove some irrelevant (such as: uuid, mac address, etc.). Set up the network under reboot: server network restart and then ping the inner network to see if it is unreachable (you can use arp-a to see which hosts are currently open). If it is passed, then probably specify how to set the network card information. Here, if you need to use eth1, you can copy eth0 to eth1, but only if you have a physical network card, you must also set up a virtual network card for the virtual machine. At this point, the internal network has been passed, and then the external network is configured. -------------------------------------------------- ----------------------------- Configure the external network ------------------ -------------------------------------------------- -----------


The fourth step, if the internal network is no problem, then take a look at the configuration of the external network (must not skip the internal network configuration to directly configure Extranet). First of all, check whether the external network has a pass, directly ping Baidu: ping www.baidu.com, if it passes, that line, you can end here. If you can't pass it, you will not be able to identify the host. Then follow the configuration below the script. First, to configure the DNS, go directly to the file: vim /etc/resolv.conf Add two lines of script.


nameserver 192.168.10.1 //DNSnameserver with gateway 8.8.8.8 //The fifth step of DNS provided by Google freely, if the previous step DNS has been configured, then you can ping first Under Baidu, can you pass? If you can't see the routing settings, the concept of routing will be awkward. Simply put: Control the routing rules inside the packets. Use the command: rounte -n to view the routing table 



You can see that there is a default gateway on the 192.168.10.1 surface in the Gateway column. When the packet cannot find the exit. When you go to this gateway, you will lose it. The other end of the router is connected to the public network, so if the default network card is configured, then it can communicate with the outside world. If you do not have a default gateway, you must manually add a default gateway: route add default gw 192.168.10.1 and then restart the network and try to communicate with the outside world.

If your Linux is not a virtual machine, the network can basically work in these few steps. But if you have a Linux system installed in a virtual machine, then configuring the network is still complicated.

-------------------------------------------- ---------------------------Virtual machine configuration network ------------------- -------------------------------------------------- ---------------------------

The virtual machine configuration network steps are basically the same as above, the only difference is the sum Host exchange problem. If you install the previous steps to configure the network to be unreachable, there is a possibility that there is a problem with the host network connection.

First look at the settings in the virtual machine, find the network, and then see what is the way to connect to the network inside the virtual machine, there are bridging and NAT, HOST-ONLY various ways can check their own Information is generally bridged. You can check the network under the host machine to see if the network in the virtual machine is forbidden (you can also see it in the change adapter). My virtual machine is a VirtualBox virtual machine with a virtualBox out of the host.


You can see that there are three networks, VirtualBox network, wireless network, and three networks connected. You can also win+r ==> cmd ==> ipconfig/All checks the status of each NIC.

There is one more thing to note: Try not to have VirtualBox and VMware installed in the same host at the same time. When installing VirtualBox, it will change the VMware network settings, so you need to reset the network after installing VirtualBox. . Another is not to refresh the virtual machine's mac address, when you refresh it means to produce a new virtual network card, the previous network card is deleted, the network will not start at the beginning, and your network card name will also Change, it may be eth1 or eth2. At this time, you can delete two files (for a time, I forgot which file seems to be: xxx-7 xxxx-9, when I boot, I will remind you that these two files cannot be read, and I want to make up the next time.

Copyright © Windows knowledge All Rights Reserved