Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Commands related to network settings of Linux network services

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Linux Network Settings

View network settings

Test the network connection

Use network configuration commands to modify network configuration files

​ this article mainly introduces some basic and commonly used Linux network setting commands in Linux and some script file configuration steps.

1. View and test the network configuration 1.ifconfig-View the address of the network interface

Format: ifconfig [network interface name] [ip address] (subnet mask)

[root@lokott] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 3556 bytes 232528 (227.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets bytes 16400 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 56 bytes 6144 (6.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56 bytes 6144 (6.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52VOUD 5400VOV 71Rd 3709 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lokott ~] # ifconfig ens33ens33: flags=4163 mtu 1500 Inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 3560 bytes 232768 (227.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0104 bytes 16400 (16.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 02.hostname-View hostname

Format: hostname

[root@lokott ~] # hostnamelokott [root@lokott ~] # cat / etc/hostnamelokott [root@lokott ~] # echo "local" > / etc/hostname [root@lokott ~] # cat / etc/hostnamelocal [root@lokott ~] # needs to be restarted before it can be set successfully Another way is to use the hostnamectl set-hostname hostname ^ c [root@lokott ~] # reboot [root@local ~] # hostnamectl set-hostname lokott [root@local ~] # su [root@lokott ~] # with lokott ^ c3.routemuri-View the route entry

-n: digital display (in centos6, whether the addition of 7 is almost the same)

[root@lokott ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault gateway 0.0.0.0 UG 10000 ens33192.168.68.0 0.0.0.0 255.255.255.0 U 10000 ens33192.168.122.0 0.0.0.0 255.255.255. 0 U 00 virbr0 [root@lokott ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.68.2 0.0.0.0 UG 10000 ens33192.168.68.0 0.0.0.0 255.255.255.0 U 10000 Ens33192.168.122.0 0.0.0.0 255.255.255.0 U 000 virbr04.netstat-- View Network connection

-n serial number

-p port number

-an all service ports

-r displays routing table information

-l displays network connections and port information in the listening state

-t tcp

-u udp

[root@lokott] # netstat-natpActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.0LISTEN 939/cupsd * LISTEN 1490/dnsmasq tcp 0 0 0.0.0.0 LISTEN 939/cupsd 22 0.0.0.0 LISTEN 941/sshd tcp 0 127.0.1 Tcp 0 0 127.0.0.1 LISTEN 1/systemd tcp6 25 0.0.0.0 LISTEN 1186/master tcp6 0 0: 11 1:: * LISTEN 1/systemd tcp6 0 0:: 22:: * LISTEN 941/sshd tcp6 0 0:: 1 LISTEN 1186/master 631: * LISTEN 939/cupsd tcp6 0 0:: 1:25:: * LISTEN 1186/master [root@lokott ~] # netstat -nuapActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 18066 0.0.0.0 * 3935/dhclient udp 0 192.168.122.1 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 53 0.0.0.0 1490/dnsmasq udp 0 0 0.0 0 0 3935/dhclient udp 67 0.0.0 0 3935/dhclient udp * 1490/dnsmasq udp 0 0 0 8 0 0 0 0 0 0 553/avahi-daemon 53 0 0 0 553/avahi-daemon: r udp 0 0 0 7 50 467 0 0 0 553/avahi-daemon: r udp6 0 0: 61206 : * 3935/dhclient [root@lokott ~] # netstat-r / / same as route Kernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Ifacedefault gateway 0.0.0.0 UG 2000 ens33192.168.68.0 0.0.0.0 255.255. 255.0 U 000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 000 virbr05.traceroute-- Test the network node passed from the current host to the target host [root@lokott ~] # traceroute 127.0.0.1traceroute to 127.0.0.1 (127.0.0.1) 30 hops max, 60 byte packets 1 localhost (127.0.0.1) 0.030 ms 0.007 ms 0.035 ms [root@lokott ~] # traceroute 192.168.10.11traceroute to 192.168.10.11 (192.168.10.11), 30 hops max 60 byte packets 1 gateway (192.168.68.2) 0.154 ms 0.085 ms 0.087 ms 2 * 3 * 4 * 5 * 6 * 7 * ^ C [root@lokott ~] # 6.nslookupML-Test DNS domain name resolution [root@lokott] # nslookup www.taobao.comServer: 192.168.68.2Address: 192.168.68.resolutions 53Non-authoritative answer:www.taobao.com canonical name = www.taobao.com.danuoyi.tbcache.com.Name: www.taobao.com.danuoyi.tbcache.comAddress: 111.3.79.235Name: www.taobao.com.danuoyi.tbcache.comAddress: 111.3.79.234Name: www.taobao.com.danuoyi.tbcache.comAddress: 211.138.124.238

Add: the dos interface of Windows system is also applicable.

Second, set the network address parameter

1. Temporary configuration-use when debugging the network

two。 Fixed configuration-changes to the configuration file will not take effect until the network service is restarted or the host is restarted, which is equivalent to permanent configuration.

7.ifdown and ifup are disabled, Activate network interface [root@lokott ~] # ifconfig ens33:0 192.168.155.55 / / Virtual interface configuration [root@lokott ~] # ifconfig ens33:0ens33:0: flags=4163 mtu 1500 inet 192.168.155.55 netmask 255.255.255.0 broadcast 192.168.155.255 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) [root@lokott ~] # ifconfig ens33:0 down [root@lokott ~] # ifconfig ens33: 0ens33:0: flags=4163 mtu 1500 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) [root@lokott ~] # ifconfig ens33:0 192.168.155.55 [root@lokott ~] # ifdown ens33:0 usage: ifdown [root@lokott ~] # ifdown ens33 successfully disconnected the device 'ens33'. [root@lokott ~] # ifconfig ens33ens33: flags=4163 mtu 1500 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 5048 bytes 329861 (322.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 490 bytes 46907 (45.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lokott] # ifconfig ens33:0ens33:0: flags=4163 mtu 1500 ether 00:0c:29:56: D3root@lokott 4a txqueuelen 1000 (Ethernet) [root@lokott ~] # ifup ens33 connection has been successfully activated (D-Bus activity path: / org/freedesktop/NetworkManager/ActiveConnection/6) [root@lokott ~] # ifconfig ens33ens33: flags=4163 mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 5082 bytes 332183 (324.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 514 bytes 50940 (324.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 08.route add, Delete static route record [root@lokott ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault gateway 0.0.0.0 UG 1000 ens33192.168.68.0 0.0.0.0 255.255.255.0 U 10000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 virbr0 [root@lokott ~] # route add-net 192.168.10.0 nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 24 gw 192.168.122.1 [root@lokott ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.68.2 0.0.0.0 UG 1000 ens33192 .168.10.0 192.168.122.1 255.255.255.0 UG 00 virbr0192.168.68.0 0.0.0.0 255.255.255.0 U 10000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 virbr0 [root@lokott ~] # route del-net 192.168.10.0 route 24 / Delete routing record [root@lokott ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.68.2 0.0.0.0 UG 10000 ens33192.168.68.0 0.0.0.0 255.255.255.0 U 100 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 000 virbr0 [root@lokott ~] # route del default gw 192.168.68.2 / / Delete the default gateway [root@lokott ~] # route add default gw 192.168.68.2 / / add the default gateway 9. Network interface profile [root@lokott ~] # cat / etc/sysconfig/network-scripts/ifcfg-ens33 TYPE= "Ethernet" / / Type is Ethernet proxy _ METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "dhcp" / / dynamically acquire DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "ens33" / / the network card name is ens33UUID= "5785d9d2-2603-4b14-bbfb-d95f6545e260" DEVICE= "ens33" / / set the network interface name to ens33ONBOOT= "yes" / / set the network interface to activate [root@lokott ~] # when the Linux system starts

Of course, we can set the static ip address as follows (be sure to restart the network service):

[root@lokott ~] # vim / etc/sysconfig/network-scripts/ifcfg-ens33 [root@lokott ~] # cat / etc/sysconfig/network-scripts/ifcfg-ens33 TYPE= "Ethernet" none "BROWSER_ONLY=" no "BOOTPROTO=" static "DEFROUTE=" yes "IPV4_FAILURE_FATAL=" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes IPV6_FAILURE_FATAL=" no "IPV6_ADDR_GEN_MODE=" stable-privacy "NAME=" ens33 "UUID=" 5785d9d2-2603-4b14 -bbfb-d95f6545e260 "DEVICE=" ens33 "ONBOOT=" yes "IPADDR=" 192.168.68.130 "NETMASK=" 255.255.255.0 "GATEWAY=" 192.168.68.2 "[root@lokott] # systemctl restart network [root@lokott] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20 ether 00:0c:29: 56:d3:4a txqueuelen 1000 (Ethernet) RX packets 5803 bytes 377581 (368.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 552 bytes 55914 (54.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets Bytes 16496 (16.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 168bytes 16496 (16.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52lav 540071 Vista 3709 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lokott ~] # 10. Domain name resolution profile

1) specify the server address information that provides DNS resolution for the local machine

[root@lokott ~] # cat / etc/resolv.conf # Generated by NetworkManagersearch localdomainnameserver 192.168.68.2 [root@lokott ~] #

2) Local host mapping file

[root@lokott ~] # cat / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

​ can generally store the host information that you often need to visit here, according to the mapping table here, you can find out whether there is a corresponding record, and no longer go to the DNS server to query, so as to improve the speed of the Internet. However, if the error is added, an exception will occur.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report