linux network settings

Posted by mecha_godzilla on Fri, 07 Jan 2022 01:51:55 +0100

View network configuration

Maximum mtu packet transfer rate

View network interface information ifconfig

  • View all active network interface information
    • Execute ifconfig command
  • View specified network interface information
ifconfig network interface
[root@localhost ~]# ifconfig ens33
ens33 flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet netmask broadcast
inet6 fe80.9106:d38b:670d:1a89 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:3a:81:cc txqueuelen 1000(Ethernet)
..//Omit some contents

View host name hostname

  • hostname command
    • View or set the current hostname
hostname[host name]((Provisional)
  • Example
[root@localhost ~]# hostname

View the route table entry route

route command

View or set routing table information in the host

route [-n]


[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway       Genmask      Flags    Metric    Ref    Use    lface       UG       100       0      0     ens33    U        100       0      0     ens33

View network connectivity netstat

  • netstat command
    • View the network connection status, routing table, interface statistics and other information of the system
netstat [option]
  • Common options
    • -a,-n,-p,-t,-u,-r
[root@localhost~]# netstat -anpt | grep ":80"
tcp60   0  :::80  :::*  LISTEN  20563/httpd

Get socket statistics ss

  • ss command
    • Check the network connection of the system and obtain socket statistics
ss [option]
  • Common options
    • -t,-u,-n,-l,-p,-a,-r
[root@localhost ~]# ss -t state established
Recv-Q  Send-Q   Local Address:Port   Peer Address:Port
0       96

Test network connection

Test network connection ping

  • ping command
    • Test network connectivity
ping[option]Target host
  • Example
[root@localhost ~]# ping
PING ( bytes of data.
64 bytes from icmp_seq=2 ttl=128 time=0.274 ms
^C  Press Ctrl+C abort test 
--- ping statistics---
2 packets transmitted, 2 received,0% packet loss, time 1162ms
rtt min/avg/max/mdev = 0.274/0.484/0.694/0.210 ms

Trace packet traceroute

  • traceroute command
    • Test the network nodes passing from the current host to the destination host
traceroute Destination host address
  • Example
[root@localhost ~]# traceroute
traceroute to (,30 hops max, 40 byte packets
1 ( ms 15.581 ms 15.881 ms
2 ( ms 19.995 ms 19.942 ms

Domain name resolution nslookup

  • nslookup command
    • Test DNS domain name resolution
nslookup Destination host address [DNS server address]
  • Example
[root@localhost ~]# nslookup
Server:     DNS server address
Non-authoritative answer:
Name:    Analytic IP address

Using the network configuration command

How to set network parameters

  • Temporary configuration - use commands to adjust network parameters

    • It is simple and fast, and can directly modify the network parameters in operation
    • Generally, it is only suitable for use in the process of debugging the network
    • After the system is restarted, the modifications will be invalid
  • Fixed settings - modify network parameters through the configuration file

    • Modify the configuration file of various network parameters
    • It is suitable for setting fixed parameters on the server
    • It will not take effect until the network service is overloaded or restarted

Set network interface parameter ifconfig

  • Set the IP address and subnet mask of the network interface
ifconfig network interface ip address [netmask Subnet mask]
ifconfig network interface ip address [/Subnet mask length]
  • Disable or reactivate the network card
ifconfig network interface up 
ifconfig network interface down
  • Set virtual network interface
ifconfig network interface:Serial number IP address

Set route record

  • The routing record added to the specified network segment
route add -net Network segment address gw IP address
  • Delete the routing record to the specified network segment
route del -net Network segment address
  • Adds a default gateway record to the routing table
route add default gw IP address
  • Delete the default gateway record in the routing table
route del default gw IP address

Modify hostname hostname

  • hostname command
    • Set host name
hostname Host name


[root@localhost ~]# hostnamelocalhost.localdomain
[root@localhost ~]# hostname www.bdqncom
[root@localhost ~]# hostname
[root@localhost ~]# bash enables a new Shell session
[root@www ~]#

Modify network profile

Network interface profile

  • /Under / etc / sysconfig / network scripts /
    • ifcfg-ens33: configuration file of the first Ethernet card
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-*

Network interface profile

  • /Under / etc / sysconfig / network scripts /
    • ifcfg-ens33: configuration file of the first Ethernet card
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33

Enable and disable network interface configuration

  • Restart network service
[root@localhost ~]# systemctl restart network
  • Disable and enable network interface
[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33

Domain name resolution profile

  • /etc/resolv.conf file
    • Save the IP address of the DNS server that this machine needs to use
[root@localhost ~]# vi /etc/resolv.conf
search localdomain

Note: CentOS 7 needs to be installed in NetworkManager Set dns=none in the main section of the conf file and restart the NetworkManager service, or use the nmcti command newly added by CentOS7 to set it

Local host mapping file

  • /etc/hosts file
    • Save the mapping record of host name and IP address
[root@localhost ~]# cat /etc/hosts localhost localhost.localdomain localhost4 localhost4.
  • Comparison between hosts file and DNS server
    • By default, the system first looks for the parsing record from the hosts file
    • The hosts file is only valid for the current host
    • The hosts file can reduce the DNS query process and speed up access


  • View network configuration
    • ifconfig,hostname,route,netstat,ss
  • Test network connection
    • ping,traceroute,nslookup,dig
  • Set network address parameters
    • Temporary configuration, permanent configuration

Topics: Linux network server