Linux Network Configuration Commands

Under Linux NIC naming rules: eth0, eth1. First Ethernet card, and the second block. lo is the loopback interface, its fixed IP address is, mask 8. It represents your machine itself.

Ifconfig is the view card information

ifconfig [Interface]

The interface is optional, and if not this information is displayed for all network cards in the system. If you add this option to display the specified card information.

For example; ifconfig eth0

First line: Connection Type: Ethernet (Ethernet) HWaddr (hardware mac address)

Second row: NIC IP address, subnet mask

The third line: UP (on behalf of the NIC turned on) Running (on behalf of the network adapter cable is connected) MULTICAST (support multicast) MTU: 1500 (Maximum Transmission Unit): 1500 bytes

Fourth, the five elements: receive, send the packet statistics

Seventh row: receiving, sending a number of data bytes statistical information.

(1) to configure the IP address of eth0 to activate the device at the same time.

(2) Configuration the alias eth0 device eth0: 1 IP address, and add a route.

(3) to activate the device.

(4) to disable the device.

(5) The view specified network interface configuration.

(6) all network interface configuration.

2, the route command to configure and view the configuration of the kernel routing table

For example:

(1) Add a route to the host.

(2) added to the routing of the network.

(3) Add the default gateway.

(4) the configuration of the kernel routing table.

(5) Delete route.

For two points 1 and 2 can use the following statement:

Ifconfig eth0 netmask

Route gw

Service network restart

Traceroute command packet to the destination host through routing

For example:

4, the ping command to test network connectivity

For example:

5, the netstat command to display network status information

Main purpose: View the connection status of the network (only TCP, UDP invalid), check the interface configuration information, check the routing table, to obtain the system

Taking into account information. TCP, UDP port status display obtained without parameters, because UDP is a connectionless protocol, so the state of its meaningless. Common

State: ESTABLISHED, LISTENING, TIME-WAIT, respectively, in a connected state, waiting for a connection, close the connection. netstat program

Several parameters option, the user can be used to view the information on different aspects of the network, its parameters are described below:

-A: option to show all configured interface

-I: option to display interface statistics

-N: options for the IP address in digital form

-R: option displays the kernel routing table

-S: option means that the value of the counter.

For example:

(1) Display Network Interface Status.

(2) Show all monitoring server Socket and Socket program information.

(3) Show the kernel routing table information.

(4) shows the connection status of the TCP / UDP transport protocol.

Hostname change the hostname

For example;

7 arp command to configure and view the ARP cache

For example:

(1) View the ARP cache.

(2) Add an IP address and MAC address of the corresponding record.

(3) Delete an IP address and MAC address of the corresponding cache records.

Ifup command is used to start the specified period of inactivity LAN equipment

This command is similar to the ifconfig up command. Ifdown command is used to stop the specified activities LAN equipment, the command ifconfig down command

Similar. The two command format is as follows:

the ifup NIC device name

the ifdown card device name

Nslookup queries the DNS database user-level commands

exit command: to exit nslookup command.

command of lserver: Find the specified domain name server and set it as the default domain name server.

server command: lserver of similar resolve another domain name server and set it as the default server, except that the command uses the current tacit

Put the server to resolve.

the set command: modify the operating parameters, it is also nslookup most commonly used commands, use the operating parameters of the operating parameters such as the nslookup procedures set command.

Operating parameters: set class set the query type, under normal circumstances, Internet.

Set debug mode/set nodebug: set to a non-debug mode

set d2 set debug mode. / Set nod2: set to a non-detailed debug mode.

set [no] defname the set defname will automatically add the default domain name after all did not add the name of the “o”. It is the default.

set domain to set the default domain name.

The SET PORT DNS the default port of 53, this command can set a different port, generally used for debugging.

Set the q (querytype), change the type of information. The default type A record

set recurse set the query type is recursive;

set retry set the number of retries. The default value is 4.

set root to set the default root server.

set timeout set to wait for the response time limit (in seconds), the excess is the time-out, if it can retry will double the long timeout value, re-

New Query. The default timeout value is 5 seconds.

10 tcpdump command is used to monitor TCP / IP connection and directly read the data link layer packet header information

The user can specify which data packets are monitored, which control the display format. For example, to monitor all communication between Ethernet, perform the following command


In fact, the tcpdump command format:

for tcpdump [- options] [-c number] [-F file name] [-i network interface] [-r file

Name] [-s snaplen]

[-T type] [-w filename] [expression]

The tcpdump command option parameters xia shown. Tcpdump command expression is a regular expression, tcpdump use it as a filter reported

Conditions, if a packet satisfies the conditions of the expression, then the packet will be captured. If you did not give any conditions, all the letters in the network

Interest packet will be intercepted.

the tcpdump command Options Introduction: Parameters Field Description

-A network address and broadcast address into a name;

-D will match the code of the packet is given to the assembler format that people can understand;

-Dd will match the code of the packet is given to the format of the c language program segment;

-DDD will match the packet code is given in decimal form;

-E print out the data link layer header information in the output line;

-F the external Internet address printed out in the digital form;

-L Make stdout line buffered;

-N Do not network address into a name;

-T does not print a timestamp for each output line;

-V output slightly more detailed information, such as IP package can include TTL and service type information;

-Vv output of the detailed packet information;

-C received after the specified number of packets, tcpdump stops;

-F expression read from the specified file, ignoring other expressions;

-I specify the network interface of the listener;

-R read from the specified file package (package-w option);

– W direct packet writing the file, do not analyze and print out;

-T will listen to the packets directly explain specify the types of messages, a common type

RPC (remote procedure call) and SNMP (Simple Network Management Protocol 😉

11 network configuration files and procedures

1, network settings / etc / sysconfig / network file is used to specify the server on the network configuration information, including the control and network-related documents and guardian

Parameters for the behavior of the program.

/ Etc / rc.d / init.d / network restart

2, the mapping between the port number and server name / etc / services

3, the configuration name parser / etc / host.conf

4, configure the DNS client / etc / resolv.conf

5, using the netconfig program to configure the network