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

Fundamentals of Linux CentOS 7 Network configuration

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

View host name

Hostname command: view or set the current hostname

Modify host name

Hostnamectl set-hostname new host name command: modify the current host name

Modify directly in the configuration file "/ etc/sysconfig/network"

View network interface information

Ifconfig [Network Interface name] command: view the information of the specified network interface. If you do not specify the interface, all interface information is displayed.

Here are a few important parameters to explain:

Inet 192.168.52.131 / / IP address netmask 255.255.255.0 / subnet mask broadcast 192.168.52.255 / broadcast address inet6 fe80::8629:c3e2: 139c:884a / / ipv6 address ether 00:0c:29:7a:41:33 / / MAC address how to set network parameters:

Temporary configuration: ifconfig network interface name IP address command-use command to adjust network parameters

The network parameters can be modified quickly and directly, which is generally suitable for use in the process of debugging the network, and the changes made after the system restart will disappear.

Fixed settings: modify the network parameters by modifying the configuration file, which is suitable for setting fixed parameters on the server. It will not take effect until the network service or system is restarted.

Prohibition and activation of network card

Disable the network card: ifconfig network interface down

[root@localhost] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255 inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20. / / omit part lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10.. / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet).. / / omit part [root@localhost ~] # ifconfig ens33 down [root@localhost ~] # ifconfiglo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10. / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet).. / / omit part of the content

Enable network card: ifconfig network interface up

[root@localhost ~] # ifconfiglo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10. / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet).. / / omit part [root@localhost ~] # ifconfigens33 up [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255 inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20 ether 00:0c:29:7a:41:33 txqueuelen 1000 (Ethernet). . / / omit part lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10.. / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)

You can also use the command "ifup network interface" to enable the network interface, and the command "ifdown network interface" to turn off the network interface. Restarting a network service usually uses the command "service network restart" or "systemctl restart network".

Set up the virtual network interface:

Ifconfig network interface: serial number IP address Note: the virtual network interface is directly deleted when the virtual network interface is closed and cannot be reopened.

[root@localhost] # ifconfig ens33: flags=4163 mtu 1500 inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255 inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20. / / omit part lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10.. / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet).. / / omit part [root@localhost ~] # ifconfigens33: 0 192.168.100.100 [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255 inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20. / / omit part of the content ens33:0: flags=4163 mtu 1500 inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255 ether 00:0c:29:7a:41:33 txqueuelen 1000 (Ethernet) lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10. . / / omit part of virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet).. / / omit part of the content to view the network connection

Netstat command: view the system's network connection status, routing table, interface statistics, etc.

Common options:

-a: list all current connections-n: disable domain name resolution-p: view process information-t: list TCP protocol connections-u: list UDP protocol connections-r: print kernel routing information

View routing table entries

Route command: view or set routing table information in the host, similar to "netstat-r"

In the Linux6 version, "0.0.0.0" is displayed in the form of "*", and only by adding the "- n" option can it be displayed as "0.0.0.0".

Set up routing record

Route record added to the specified network segment:

Route add-net network segment address gw IP address

Delete the route record to the specified network segment:

Route del-net network segment address

Add 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

Test the network connection

Ping command: test network connectivity, press [Ctrl+C] to terminate the test

Tracking packet

Traceroute destination host address command: test the network node passing from the current host to the destination host

When our network cannot communicate properly, we can use the traceroute command to see which node has gone wrong.

Domain name resolution

Nslookup destination host address [DNS server address] command: test DNS domain name resolution

DNS address change

You can modify it directly in the configuration file "/ etc/resolv.conf"

Local host mapping file

"/ etc/hosts" saves the mapping record between hostname and IP address

By default, the system first looks for the resolution record from the hosts file. It will be parsed by the DNS server only if it cannot be found. The hosts file can speed up the access, but it is only valid for the current host.

Scp command remote replication

Synchronize local files to a remote server

Scp local synchronization file path user @ IP: remote server file path

We add two DNS mapping records to the "/ etc/hosts" file of the host01 host, and then synchronize it to the host02 host through the scp command on the host01 host.

Synchronize remote server files locally

Scp user @ IP: remote server file path local synchronization file path

We add two more DNS mapping records to the "/ etc/hosts" file of the host02 host, and then synchronize it from the host02 host on the host01 host.

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