BKJIA exclusive Article: This article is a continuation of your Linux Server-hardware article and the second article in the series "your Linux Server. I hope that after reading this article, you can clearly understand the Network Situation of your server and easily configure its network environment. After the Linux server is installed, configuring its network environment is the function of every system administrator.
I. server network configuration
When configuring the server network, you can use setup or system-config-network to configure the image.
The NIC configuration file is/etc/sysconfig/network-scripts/ifcfg-eth0 and takes effect directly with service network restart
- [root@linpcl root]#cat /etc/sysconfig/networking/devices/ifcfg-rth0
- DEVICE=eth0
- ONBOOT=yes
- BOOTPROTO=static
- IPADDR=192.168.0.2
- NETMASK=255.255.255.0
- GATEWAY=192.168.0.1
The GATEWAY option is acceptable.Set gateway ParametersHere, pay attention to the ONBOOT option, which indicates whether the NIC is started with the system startup. This option must be set to on
Here we will introduce two parameters that are not too common.
USERCTL = no, that is, normal users are not allowed to modify the nic peerdns = yes, which indicates that DNS obtained from DHCP is allowed to overwrite the local DNS
View the status of all NICs on the local machine ifconfig-a. For more advanced Nic routing commands, use ip addr, in particular, when your server is bound to a virtual VIP by keepalived, It is very convenient to view the local route netstat-rn or route.
Add a local network route using the command route add-net 172.16.6.0 netmask 255.255.255.255.0 gw 172.16.2.25, that is, add a network 172.16.6.0/24 to go through 172.16.2.254. This address can also be understood as your next hop address.
Run the route del-net 172.16.86.0/24 command to delete a route.
If you want to permanently edit available files
vim /etc/sysconfig/network-scripts/route-eth0172.16.6.0/24 via 172.16.2.25
View the local DNS server cat/etc/resolv. conf view the host name hostname view the IP address of the Host Name/etc/hosts
Its execution sequence is better than that of DNS, and is mostly used in cluster environments, such as Heartbeat. It also has a wonderful use. When testing in a DNS environment, you can directly change this file on the server, for the purpose of priority resolution, view the network device that is directly connected to the local machine using the command arp
Here we will introduce a very useful tool, mii-tool, to determine which Nic is connected to the network cable, and colleagues rely on the network cable to determine which Nic is connected to the network cable is inefficient
- [root@mail~]#mii-tool
- eth0: negotiated 100baseTx-FD flow-control, link ok
- SIOCGMIIPHY on 'eth1' failed: Resource temporarily unavailable
You may not feel this text, but it is very useful when you arrive at the data center. Especially for servers with many NICs, I see that one of the most popular Linux servers is bound with six NICs.
2. view the network connection status of your server
- netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
- LAST_ACK 14
- SYN_RECV 348
- ESTABLISHED 70
- FIN_WAIT1 229
- FIN_WAIT2 30
- CLOSING 33
- TIME_WAIT 18122
Status: Description
◆ CLOSED: No connection is active or in progress
◆ LISTEN: the server is waiting for a call
◆ SYN_RECV: a connection request has arrived and is waiting for confirmation.
◆ SYN_SENT: The application has started. Open a connection.
◆ ESTABLISHED: normal data transmission status
◆ FIN_WAIT1: The application says it has been completed
◆ FIN_WAIT2: the other side has agreed to release
◆ ITMED_WAIT: wait until all groups die.
◆ CLOSING: both sides attempt to close at the same time
◆ TIME_WAIT: the other side has initialized a release.
◆ LAST_ACK: waiting for all groups to die
The ESTABLISHED value is actually the current number of concurrent threads, which can be focused on; in addition, you can focus on the value of TIME--WAIT. For high-concurrency Squid servers in Linux, the number of TCP TIME_WAIT sockets often reaches two or 30 thousand, and the server is easily dragged to death. By modifying Linux kernel parameters, you can reduce the number of TIME_WAIT sockets on the Squid server. For more information, see my article on optimizing Linux production servers.