Linux network configuration command
Nic naming rules in Linux: eth0 and eth1. The first Ethernet Card and the second card. Lo is the loopback interface, its IP address is fixed to 127.0.0.1, And the mask is 8 bits. It represents your machine.
1. ifconfig is used to view Nic Information
Ifconfig [interface]
Interface is optional. If this option is not added, information about all NICs in the system is displayed. If this option is added, the specified Nic information is displayed.
For example, ifconfig eth0
Eth0 link encap: Ethernet
Hwaddr 00: 0C: 29: F3: 3B: F2
Inet ADDR: 192.168.0.10 bcast: 192.168.0.255 mask: 255.255.255.0
Up broadcast running Multicast MTU: 1500 Metric: 1
RX packets: 78 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 104 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 100
RX Bytes: 11679 (11.4 KB)
TX Bytes: 14077 (13.7 KB)
Interrupt: 10 Base Address: 0x1080
You can see:
Line 1: Connection Type: Ethernet (Ethernet) hwaddr (hardware MAC address)
Line 2: IP address, subnet, and mask of the NIC
Row 3: Up (indicating that the network card is enabled) running (indicating that the network card is connected) multicast (supporting Multicast) MTU: 1500 (maximum transmission unit): 1500 bytes
4. Five Elements: Statistics on received and sent data packets
Row 7: number of bytes of received and sent data.
(1) configure the IP address of eth0 and activate the device.
# Ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
(2) configure the IP address of the eth0 alias device eth0: 1 and add a route.
# Ifconfig eth0: 1 192.168.1.3
# Route add-host 192.168.1.3 Dev eth0: 1
(3) activate the device.
# Ifconfig eth0: 1 up
(4) disable the device.
# Ifconfig eth0: Down
(5) view the configuration of the specified network interface.
# Ifconfig eth0
(6) view all network interface configurations.
# Ifconfig
2. Configure and view the kernel route table by using the route command
For example:
(1) route added to the host.
# Route add-host 192.168.1.2 Dev eth0: 0
# Route add-host 10.20.30.148 GW 10.20.30.40
(2) route added to the network.
# Route add-net 10.20.30.40 netmask 255.255.255.248 eth0
# Route add-net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41
# Route add-net 192.168.1.0/24 eth1
(3) Add a default gateway.
# Route add default GW 192.168.1.1
(4) view the configuration of the kernel route table.
# Route
(5) delete a route.
# Route del-host 192.168.1.2 Dev eth0: 0
# Route del-host 10.20.30.148 GW 10.20.30.40
# Route del-net 10.20.30.40 netmask 255.255.255.248 eth0
# Route del-net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41
# Route del-net 192.168.1.0/24 eth1
# Route del default GW 192.168.1.1
You can use the following statement to implement steps 1 and 2:
Ifconfig eth0 172.16.19.71 netmask 255.255.255.0
Route 0.0.0.0 GW 172.16.19.254
Service Network restart
3. The traceroute command shows the route through which the data packet arrives at the target host.
For example:
# Traceroute www.sina.com.cn
4. Ping the command to test network connectivity
For example:
# Ping www.sina.com.cn
# Ping-C 4 192.168.1.12
5. Run the netstat command to display network status information.
Main purposes: view the network connection status (only valid for TCP, no for UDP)Check the interface configuration information, check the route table, and obtain the unified
Information. WithoutThe TCP and UDP port status is displayed because UDP is not connected.So the status is meaningless. Common
Status: established,Listening and time-Wait indicate that they are in the connection status, waiting for connection,Close the connection. NetstatProgramYes
Several Parameter options that can be used to view the networkParameters are described as follows:
-A: The option is to display all configured interfaces.
-I: The option is to display interface statistics.
-N: the option is to display IP addresses in numbers.
-R: displays the kernel route table.
-S: indicates the counter value.
For example:
(1) display network interface status information.
# Netstat-I
(2) display the socket and the program using the socket of all monitoring servers.
# Netstat-LPE
(3) display kernel route table information.
# Netstat-R
# Netstat-NR
(4) display the connection status of TCP/UDP transmission protocol.
# Netstat-T
# Netstat-u
6. Change the Host Name
For example;
# Hostname myhost
7. Configure and view ARP cache using ARP commands
For example:
(1) view the ARP cache.
# ARP
(2) Add a record corresponding to the IP address and MAC address.
# ARP-s 192.168.33.15 00: 60: 08: 27: Ce: B2
(3) Delete A cache record corresponding to an IP address and a MAC address.
# ARP-d192.168.33.15
8. The IFUP command is used to start the specified inactive Nic device.
This command is similar to the ifconfig up command. The ifdown command is used to stop a specified Active Nic device. This command is similar to the ifconfig down command.
. The two commands are in the following format:
IFUP Nic device name
Ifdown Nic device name
9. NSLookup user-level command for querying DNS databases
Exit command: Exit NSLookup command.
Lserver command: Find the specified Domain Name Server and set it to the default Domain Name Server.
Server command: similar to lserver, this command resolves another Domain Name Server and sets it as the default server. The difference is that this command uses the current
Identify the server for resolution.
SET command: Modify the working parameters. It is also the most common command in NSLookup. Its working parameters include the Working Parameters in the SET command of the NSLookup program.
Work parameter description: Set class sets the query type, which is generally I nternet.
Set de bug setting debugging mode/set nodebug: Set to non-debugging mode
Set D2 sets the detailed debugging mode. /Set nod2: Set to non-detailed debugging mode.
Set [No] defname is set to defname, and the default domain name is automatically added after all "O" names are not added. It is the default method.
Set domain to set the default domain name.
The default port of set port DNS is 53. You can use this command to set its port, which is generally used for debugging.
Set Q (querytype) changes the type of the queried information. The default type is a record.
Set recurse to set the query type to recursion;
Set retry to set the number of retries. The default value is 4.
Set root to set the default root server.
Set timeout sets the time limit for waiting for a response (unit: seconds). Timeout is triggered when the response is exceeded. If you can try again, the timeout value will be doubled and the response will be duplicated.
New query. The default timeout value is 5 seconds.
10. The tcpdump command is used to monitor TCP/IP connections and directly read the header information of data packets at the data link layer.
You can specify which data packets are monitored and which control formats are to be displayed. For example, to monitor communication between all Ethernet connections, perform the following steps:
Order:
# Tcpdump-I eth0
In fact, the format of the tcpdump command is:
Tcpdump [-Option] [-C quantity] [-F file name] [-I network interface] [-r File
Name] [-s snaplen]
[-T type] [-W file name] [expression]
The option parameters in the tcpdump command are described in Xia. The expression in the tcpdump command is a regular expression, which is used by tcpdump as a filter
If a packet meets the expression conditions, the packet will be captured. If no conditions are given, all messages on the network
The information packet will be intercepted.
Options of the tcpdump command:Parameter options
-A converts a network address and broadcast address into a name;
-D: matchCodeGiven in a collection format that people can understand;
-Dd matches the information package codeC LanguageThe format of the program segment;
-DDD provides the matching information package code in decimal format;
-E prints the header information of the data link layer in the output line;
-F print the Internet address in numbers;
-L changes the standard output to the buffer row format;
-N does not convert the network address into a name;
-T no timestamp is printed on each output line;
-V outputs a slightly detailed information. For example, the IP package can contain TTL and service type information;
-VV: Output detailed message information;
-C. After receiving the specified number of packages, tcpdump stops;
-F Read the expression from the specified file and ignore other expressions;
-I indicates the network interface of the listener;
-R reads packets from a specified file (these packets are generally generated using the-W option );
-W directly writes the package into the file and does not analyze or print it out;
-T directly interpret the packet to be listened to as a specified type of message. Common types include
RPC (Remote process call) and SNMP (Simple Network Management Protocol ;)
11.Network configuration files and programs
1. Network Settings/etc/sysconfig/network this file is used to specify network configuration information on the server, including network-related control files and daemons
Parameters of program behavior.
/Etc/rc. d/init. d/network restart
2. ing between port numbers and server names/etc/services
3. Configure the name parser/etc/host. conf
4. Configure DNS Client/etc/resolv. conf
5. Use the netconfig program to configure the network