Use IP commands instead of ifconfig to configure Linux Networks

Source: Internet
Author: User
Use IP commands instead of ifconfig to configure Linux Network-general Linux technology-Linux technology and application information. The following is a detailed description. [I = s] This post was last edited by go11 at, January 5 ,.

[TechTarget China original] in order to better overhaul your Linux network, you need to ensure that IP-related parameter settings on all NICs are correct. If you are using a Dynamic Host Configuration Protocol (DHCP) to configure the server, in most cases, this is probably already set automatically. However, if you want to configure a server that tries to avoid system errors, You need to manually set some IP information and configurations.

To determine whether the IP parameter settings on your server are correct, first confirm the following:

Are your IP addresses correctly used?
Is the subnet mask set correctly?
Are you sure you have used the correct tool to monitor your IP configuration?
Can you contact the default gateway?
Can you access the Domain Name System (DNS) server?

We will find that these should be set in advance on the computer. At the same time, there are still some problems related to IP settings outside of your network system. This article will not be too much involved. If not necessary, it is generally not recommended that the system administrator modify it at will.

   IP commands and ifconfig tools

Many people are still accustomed to using ifconfig to monitor and configure their Linux network. However, we recently discovered that the IP command tool is also a good tool for monitoring and configuring networks. However, although it is compatible with most system configurations, it is not all compatible.

The information set using the ip tool is not displayed when you use ifconfig to monitor the system. Although it seems unrelated, it is not because most system tools used in different Linux versions depend on ip tools. This means that you may lose some configurations set for monitoring using ifconfig.

Let's look at an example. Use the following command to add a random IP address to your eth0 Nic interface:

Ip address add dev eth0 10.100.100.1/24

Use the ifconfig command to check your Nic configuration. As shown in Listing 1, the address information just added does not seem to be visible.

Listing 1: (IP address information is not always displayed in ifconfig)
Uppernavik:/# ifconfig eth0
Eth0 Link encap: Ethernet HWaddr 00: 15: C5: 81: 7B: 46
Inet addr: 192.168.1.24 Bcast: 0.0.0.0 Mask: 255.255.255.0
Up broadcast multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)
Interrupt: 17

In fact, this is not hard to understand. Because of the IP address configuration for the secondary write, the ifconfig configuration appears in different locations. You can use the IP command tool to find detailed IP address configuration information.

Even if the IP address is currently the only tool used to monitor IP address settings, there are still some things that need to be handled using ifconfig. For example, monitoring network interface traffic, including packet loss statistics. For example, when connecting to a 3G network, I like to monitor the data traffic of my ppp0 interface. The cost of connecting to 3G networks is still relatively expensive, so it is necessary to monitor traffic. In this regard, the ifconfig command is outstanding.

Once the IP address you are using passes the verification, it indicates that the network connection uses the correct address information. Next, verify the external network connection. Under normal circumstances, your computer needs to connect to other networks through a router, and all computers have a default route configuration. The most common method is to use a route. IP addresses in the same network can be connected to other networks. Generally, the last valid IP address is used for this purpose, but this is not mandatory.

There are two commands to display your current route information: route and ip route. In Listing2, you can see that these commands are output at the same time.

Listing2: (you can use route and IP route to display route information)
Uppernavik:/# ip route show
192.168.150.0/24 dev vmnet1 proto kernel scope link src 192.168.150.1
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.24
172.16.186.0/24 dev vmnet8 proto kernel scope link src 172.16.186.1
10.100.100.0/24 dev eth0 proto kernel scope link src 10.100.100.1
Uppernavik:/# route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.150.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.186.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8
10.100.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

The command information includes a list of known networks and the IP addresses used by the router to obtain the interface connecting to the computer name. The IP address of the vro to the destination network may be a local IP address (2nd in the command list ).

As you can see in the Listing 2 example, there is no big difference between the two. Information is returned through the route command and the IP route command. However, we found that some important information is lost and this computer has no default route. This means that the computer cannot establish a connection with the external network.

If the default route is not automatically added, you can use the IP route add command. For example, to add the default route of the IP address 10.0.0.254, run the following command:

Ip route add default via 10.0.0.254

From this moment on, you can establish a connection with a computer on another network.

The last step is domain name resolution. If you do not want to connect to other computers only by using an IP address, but want to use a meaningful name (such as www.example.com ). You also need the DNS service.

Generally, the DNS server you are using has already installed Internet services. However, you must tell your computer where to find your desired DNS server. To find out the Domain Name Server you need, add a line address similar to the following configuration file/etc/resolv. conf:

Nameserver 10.0.0.254

After completing these steps, you can connect them. You can use the ping command to verify that the best method is to ping the DNS domain name, but make sure that you detect that the DNS configured on the server can return information, because this is not applicable to all servers.

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.