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

Basic configuration of Linux CentOS 7 network

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

Share

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

First, view the network configuration

1. Ifconfig to check the network interface address

When the ipconfig command does not take any options and arguments, it displays all network interface information that the host has enabled.

Ens33: native network card

Lo: loop network card, generally used for local network testing.

Virbr0: virtual machine bridge network card, generally used for the connection between virtual machines within the server.

2. Use the hostname command to view and modify the host name

Use the command "hostnamectl set-hostname zhangsan" to change the hostname to zhangsan.

3. Use the route command to view route entries

The route-n command is used in Linux 6 to display the address in the router as a number, but it has been optimized in Linux7 to display as a number without adding the-n option.

4. Use the netstat command to check the network connection

-a: displays all active network connections in the current host.

-n: displays the relevant host address, port and other information in digital form.

-r: displays routing table information (netstat-n is equivalent to the command route).

-l: displays the network connection and port information in the listening state.

-t: view information about TCP protocol.

-u: view information about UDP protocol.

-p: displays the process number and process name information.

Here we combine the "- ntap" option to display all the TCP process information on the current system digitally.

Second, test the network connection

1. Use the ping command to test network connectivity

Use the ping command in the Linux system to continuously send packets to the destination host and display the feedback results. To terminate the test, press the key combination "Ctrl+C"

2. Use the traceroute command to track the routing path of the packet

Use the traceroute command to test which network nodes have passed from the current host to the destination host and to display the connection status of each intermediate node. It can be used to detect which node went wrong when the two hosts could not be put together.

3. Use nslookup command to test and resolve DNS domain name resolution.

When we can't access the website but can use the network communication APP, we can use the command nslookup to test whether there is something wrong with our domain name resolution service. The port 53 of the domain name resolution connection includes two protocols, namely, TCP and UDP,TCP are responsible for connecting UDP for resolution.

Third, use network configuration commands

1. Configuration of IP address

The configuration of IP address is divided into two types, one is temporary configuration, the other is fixed configuration.

Temporary configuration: modify through the command, and take effect immediately after the modification; the operation is simple and fast, and the execution efficiency is high; it will become invalid after restart.

Fixed configuration: modified through the configuration file, the network service needs to be restarted to take effect; the operation is relatively complex; it is permanent and valid, and the restart will not expire.

Temporarily configure the IP address "ifconfig ens33 192.168.131.158"

The permanent configuration IP address needs to be configured in the configuration file. Use the command "vim / etc/sysconfig/network-scripts/ifcfg-ens33" to enter the configuration file to modify it.

2. Bind the virtual interface to the network card

Use the command "ifconfig ens33:0 192.168.131.88"

3. Disable and activate the network interface

"ifconfig ens33 down" disables the network card ens33

"ifconfig ens33 up" reactivates the network card ens33

4. Use the command route to add and delete static route records

"route add-net 192.168.100.0Plus 24 gw 192.168.131.1" add a routing entry

"route del-net 192.168.100.0swap 24" deletes a route entry

5. Use the command route to add and delete default gateway records

"route add default gw 192.168.131.1" add default gateway

"route del default gw 192.168.131.1" Delete the default gateway

4. Configure dual network cards

First, add a new network card to the host and change the status of both network cards to host-only mode.

At this time, we can use "ifconfig" to see that a new network card ens37 has been added, but neither of the two network cards has an IP address, so we need to configure the IP address of the two network cards.

First of all, let's go to the configuration file to configure the ens33 network card.

Restart the network service to make the network card ens33 effective.

We entered the network configuration file and did not find the ens37 Nic.

Without ens37, we can make a copy of ens33 and save it as ens37.

But at this time, our ens37 can not be used immediately, because its configuration file is still ens33, we still need to make some changes to its configuration file.

Restart the network service after the modification is completed.

At this time, both of our network cards are configured.

V. modify the network configuration file

1. Host name profile

You can modify the configuration file / etc/sysconfig/network by modifying the hostname of the system in CentOS 6. When CentOS 7 modifies the host name, the configuration file to be modified is / etc/hostname.

2. Domain name resolution profile

The / etc/resolv.conf file records the address information of the DNS server used by default on this machine, and changes to the file will take effect immediately.

3. Local host mapping file

When accessing a strange domain name, first check whether the file has the corresponding record, if not, then go to the DNS server to query. Hosts files reduce the DNS query process, thus increasing the speed of the network.

Extracurricular expansion: remote synchronization of files

Remotely synchronize local files to another server in the format: scp local file path user @ ip: remote server file path

First of all, let's look at the hosts file of another server so that we can synchronize and compare.

Synchronize native hosts files to another server. "scp / etc/hosts root@192.168.131.134:/etc/hosts" → "yes" → remote server password

View the mapping file of another server to verify the synchronization results.

Synchronize files from the remote server locally. Format: scp user @ ip: remote server file path local synchronization file path

To distinguish the differences and facilitate verification of the results, let's first add a new entry to the hosts of another server.

Synchronize remote server files locally. "scp root@192.168.131.134:/etc/hosts / etc/hosts" → remote server codec.

Check the native hosts file to verify the synchronization results.

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