DebianLinux network setting command summary

Source: Internet
Author: User
Tags nslookup nslookup command
Debian Linux has powerful network functions, and the network configuration files used are different from those of other Linux distributions. 1. the basic network command 1.1ifconfigifconfig is used to display network interface information in the "active" status on the current host. # Ifocnfigeth0Linkencap: EthernetHWaddr00: 0c: 29: b5: 46: 75ine DebianLinux has powerful network functions. The network configuration file used is different from other Linux releases.

1. basic network commands

1.1 ifconfig
The ifconfig command is used to display the network interface information in the "active" status on the current host.

# Ifocnfig

Eth0 Link encap: Ethernet HWaddr00: 0c: 29: b5: 46: 75
Inetaddr: 202.193.51.211 Bcast: 202.193.51.255 Mask: 255.255.254.0
Inet6 addr: fe80: 20c: 29ff: feb5: 4675/64 Scope: Link
Up broadcastrunning multicast mtu: 1500 Metric: 1
RXpackets: 176937 errors: 0 dropped: 0 overruns: 0 frame: 0
TXpackets: 101245 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 fig: 1000
RXbytes: 194590366 (185.5 MiB) TX bytes: 10767628 (10.2 MiB)
Interrupt: 19 Base address: 0x2024

Lo Link encap: LocalLoopback
Inetaddr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopbackrunning mtu: 16436 Metric: 1
RXpackets: 16 errors: 0 dropped: 0 overruns: 0 frame: 0
TXpackets: 16 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 960 (960.0 B) TX bytes: 960 (960.0 B)

The "ifconfig-a" command is used to display information about all network interfaces (including inactive network interfaces) on the current host ), of course, if there are no inactive network interfaces, the "ifconfig-a" command and the "ifconfig" command will get the same display result.

The "ifconfigethN" command is used to display the information of the specified network interface in the current host (regardless of the status of the network interface). "N" in "ethN" indicates the serial number of the network interface in the system. For example, the first network card in the system is "eth0 ".

1.2 route command
The route command is used to display the routing information in the current linux system. from the result of the route command, you can see the subnet of the current host and the address of the default gateway.

# Route

Kernel IP routing table
Destination Gateway Genmask FlagsMetric Ref Use Iface
202.193.50.0*255.255.254.0 U 0 0 0 eth0
Default 254.51.193.202.0.0.0.0 UG 0 0 0 eth0

1.3 netstat command
The "netstat-r" command can implement the same functions as the "route" command, that is, display the routing information (route table) in the Linux system ).
"Netstat-au" shows the connection status of udp transmission protocol.
"Netstat-at" displays the connection status of tcp transmission protocol.
1.4 nslookup command
The nslookup command has two command modes: query and interaction. the query mode specifies the domain name to be queried in the nslookup command line. The format is "nslookupDomainName "; the command format of nslookup interactive mode is very simple. you can directly execute the nslookup command without any parameters and then perform the nslookup interactive state.

# Nslookup www.server110.com//query mode

# Nslookup
// Perform the nslookup interaction mode and enter the domain name to be queried
> Www.server110.com
Server: 202.103.243.112
Address: 202.103.243.112 #53

Name: www.server110.com
Address: 202.193.64.56
> Exit
// Enter exit to exit the interactive mode

1.5 ping command
"Ping <主机地址> "Is used to test whether the network connection from the current host to other hosts in the network is normal.

# Ping www.server110.com//pingthe command line will continue, go directly to the next combination key ctrl+c combination key stop pingcommand run.

"Ping-c N <目标主机地址> "Command is used to test the network connection status by using a specified number of packets.

# Ping-c 5 www.server110.com

1.6 enable/disable NICs
# Ifconfig up
# Ifconfig down

2. configure Dynamic IP address acquisition
In a large network, the client host is usually set to automatically obtain network information such as IP addresses and subnet masks from the DHCP server. Therefore, the network settings of the client can be greatly simplified. The following describes how to configure the DHCP client.

2.1 interfaces configuration file
The "interfaces" file under the "/etc/network/" directory is one of the most important network configuration files in Debian Linux. This file is used to describe the configuration information of all network interfaces on the host, this file must be configured no matter whether the Debian Linux host is used as a DHCP client or configured to use a static IP address.
The following is the configuration content of the "interfaces" file in the Debian Linux system of the DHCP client. "iface eth0 inetdhcp" sets the network interface eth0 to obtain the network address through dhcp.

# Cat/etc/network/interfaces

# This file describes thenetwork interfaces available on your system
# And how to activate them. For more information, see interfaces (5 ).

# The loopback networkinterface
Auto lo
Iface lo inet loopback

Iface eth0 inetdhcp // used to set the network interface eth0 to obtain the network configuration through the dhcp protocol

2.2 restart the network service
After changing the "interfaces" file, you need to restart the "networking" service in Debian Linux (restart.

#/Etc/init. d/networkingrestart

3. configure static IP addresses
To configure DebianLinux to use static IP addresses, you also need to configure the IP addresses in the "interfaces" file under the "/etc/network" directory. The static IP address configuration uses more configuration items in the "interfaces" file.

3.1 set the IP address of the network interface
If the host needs to configure a network interface to use a static IP address, you need to set the following content in the "interfaces" file:
Indicates that the network interface uses a static IP address.
Set the IP address of the network interface
Set the subnet mask of the network interface
Set the IP address of the default gateway
The following figure shows the content of the "interfaces" file in which eth0 is configured as a static IP address. the functions of each configuration item in the configuration file are as follows:

# This file describes the network interfaces available on yoursystem
# And how to activate them. For more information, seeinterfaces (5 ).

# The loopback network interface
Auto lo
Iface lo inet loopback

Auto eth0
Iface eth0 inetstatic // Configure eth0 to use the default static address
Address 192.168.77.htm // Set the IP address of eth0
Netmask 255.255.255.0 // Configure the subnet mask of eth0
Gateway 192.168.77.2 // Configure the default gateway of the current host

There are many other settings in the "interfaces" file. to learn more, you can use the man command to query the manual page of the "interfaces" file.

# Man interfaces

3.2 make the network configuration take effect
After setting the "interfaces" file, you must tell the system that the content of the configuration file has changed and need to be reloaded. use the ifdown command to disable the Nic first, and then use the ifup command to enable the NIC, you can reload the configuration of a specified network interface.

# Ifdown eth0
# Ifup eth0

Of course, you can restart the "networking" service to reload the network interface configuration. However, this method will affect the continuous operation of other network interfaces on the host.

3.3 manually set network interfaces
In some cases, you need to temporarily change the IP address of the current network interface. modifying the "interfaces" file is obviously troublesome (because you need to change it back). In this case, you can use the ifconfig command to manually set the IP address, after the system restarts, read the content of the "interfaces" file and restore it to the original configuration of the system.

// Use the ifconfig command to manually set the IP address of eth0
# Ifconfig eth0 192.168.77.133netmask 255.255.255.0

3.4 manually set the default gateway
After you change the IP address temporarily, you may also need to temporarily change the address of the default gateway. you can use the route command to perform this operation effectively, after the system restarts, read the content in the "interfaces" file and restore it to the original default gateway configuration of the system.
Note that before using the "route add defaultgw" command to add a gateway, you must use the "route del defaultgw" command to delete the original gateway, otherwise, the network addressing of the current host will fail.

# Route del default gw
# Route // view
# Route add default gw192.168.77.1
# Route // view

4. set the host name

4.1 View host name
The hostname command can be used to query the name of the current host at any time when the Debian Linux system is running.

4.2 modify the hostname file
The "hostname" file in the "/etc/" directory is used to configure the DebianLinux host name. when the system starts, the content in the file is read as the host name. Therefore, after modifying the "hostname" file, the modified host name in the "hostname" file takes effect until the next system is started.

// View the host name settings in the hostname

# Cat/etc/hostname


4.3 set the host name in real time
In addition to displaying the current host name of the system, the hostname command can also be set instantly, that is, the host name set through the hostname command takes effect immediately, after the system is restarted, it is set to the content in the "/etc/hostname" file.

4.4/etc/hosts
The hosts configuration file is used to map host names to IP addresses. this method is relatively simple. However, this ING is only the ing of local machines. that is to say, each machine is independent and all computers cannot access each other through hostname.
Note: There is also a/etc/hostname file in debian. This File writes the local host name directly, but it must be consistent with the local host name in/etc/hosts.
The content of/etc/hosts is generally similar to the following:
127.0.0.1 debian. at. myplace debian
Note:
Generally, the hosts content defines the host name (hostname). each act is a host. each line consists of three parts, separated by spaces. The line starting with # is not explained by the system.
Part 1: network IP address;
Part 2: host name. domain name. Note that there is a halfwidth between host name and domain name, such as localhost. localdomain
Part 2: host name (host name alias) is actually the host name;
Of course, each line can also be two parts, namely the host IP address and host name; for example, 192.168.1.195 debian
127.0.0.1 is the loop address. for example, if we do not want other machines in the Lan to see the network program we are testing, we can use the loop address for testing.
Change hosts
# Echo "127.0.0.1 debian. at. myplace debian">/etc/hosts

4.5 general method for changing the host name
The hostname command and the hostname file have their respective functions. to change the host name permanently, follow these steps:
1) set the host name to be changed in the "/etc/hostname" file to ensure that the host is set to the correct host name at the next startup.
2) use the hostname command to instantly set the new host name of the current system (the content set in the "/etc/hostname" file) to take effect, so as to avoid restarting the system because you need to change the host name.

After the preceding two steps, the current host name of Debian Linux is successfully set and continues to work.
# Echo debian>/etc/hostname
# Sed-I-e's/HOSTNAME. */HOSTNAME = "debian"/'/etc/hostname
#/Bin/hostname-F/etc/hostname <----------- F indicates reading from the file
# Hostname
# Hostname-f <----------- indicates the long hostname.

5. set the DNS server address
5.1 configure the resolv. conf file
The DNS server address of Debian Linux uses the File "/etc/resovl. conf. you can use the "nameserver" configuration item to set the IP address of the DNS server; "resolv. in the conf file, you can use "nameserver" to specify three DNS servers in sequence. once the previous DNS server fails, the system will automatically use the subsequent DNS servers.
For "resolv. the change to "nameserver" in the conf file takes effect immediately, that is, as long as the "resolv. the conf file is modified and saved. The next time the system needs to resolve the domain name, the domain name will be resolved according to the DNS server IP address specified in the file.
# Echo nameserver 8.8.8.8>/etc/resolv. conf <-------- use google public domain name
# Echo nameserver 8.8.4.4>/etc/resolv. conf

5.2 Use the nslookup command to query the DNS server
You can use the nslookup command in interactive mode to query the IP address of the DNS server used by the current system. In this way, you can verify the "resolv. conf "configuration file modification effect.

# Nslookup
Default server: 202.103.243.112
Address: 202.103.243.112 #53 // The default IP Address of the DNS server used by the system is "202.103.243.112"
> Server

# Exit

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.