Linux CentOS 7 basic network configuration

First, view the network configuration
1, ifconfig to view the network interface address
when the ipconfig command without any options and parameters, displays all information about the host network interface enabled.
ens33: This machine NIC
lo: loopback adapter, generally used for this test machine according to the machine network.
virbr0: VM bridge card, typically used to connect a virtual machine inside the server.
Linux CentOS 7 basic network configuration

2, using the hostname command to view and modify the host name
using the command "hostnamectl set-hostname zhangsan" to modify the host name zhangsan.
Linux CentOS 7 basic network configuration

3, use the route command to view the routing entry
Linux CentOS 7 basic network configuration

route -n command to display the address of the router in digital form, but in Linux7 optimization have been made, no need to add the -n option as displayed in digital form in the Linux 6.
Linux CentOS 7 basic network configuration

4, use the netstat command to view the network connection
-a: Displays the current host network connection in all activities.
-n: Displays information related to the host address and port in digital form.
-r: routing table information (netstat -n equivalent command route).
-l: Displays network connection and port information in a listening state.
-t: view the TCP protocol information.
-u: UDP protocol to view related information.
-p: display process ID, process name information.
Here we combine "-ntap" option to display the current system all TCP process information in digital form.
Linux CentOS 7 basic network configuration

Second, testing network connections
a ping command to test network connectivity
can continue to send data packets to the destination host ping command on a Linux system, and displays the result of feedback, to terminate the test, press the key "Ctrl + C" composition
Linux CentOS 7 basic network configuration

2、使用traceroute命令可以跟踪数据包经过的路由途径
使用traceroute命令可以测试从当前主机到目的主机之间经过了哪些网络节点,并显示各中间节点的连接状态。可以用来检测当两台主机无法拼通时是哪个节点出了问题。
Linux CentOS 7 basic network configuration

3、使用nslookup命令测试解析DNS域名解析
当我们无法访问网站却可以使用网络通讯APP时,就可以使用命令nslookup测试是不是我们的域名解析服务出了问题。域名解析连接的53端口包括了两个协议,分别是TCP与UDP,TCP负责连接UDP负责解析。
Linux CentOS 7 basic network configuration

三、使用网络配置命令
1、IP地址的配置
IP地址的配置分为两种,一是临时配置,二是固定配置。
临时配置:通过命令进行修改,修改后即刻生效;操作简单快捷,执行效率高;重启后将会失效。
固定配置:通过配置文件进行修改,需要重启network服务才会生效;操作相对复杂些;永久有效,重启不会失效。
临时配置IP地址“ifconfig ens33 192.168.131.158”
Linux CentOS 7 basic network configuration

永久配置IP地址需要进入配置文件进行配置。使用命令“vim /etc/sysconfig/network-scripts/ifcfg-ens33”进入配置文件进行修改。
Linux CentOS 7 basic network configuration
Linux CentOS 7 basic network configuration

2、为网卡绑定虚拟接口
使用命令“ifconfig ens33:0 192.168.131.88”
Linux CentOS 7 basic network configuration

3、禁用、激活网络接口
“ifconfig ens33 down”禁用网卡ens33
Linux CentOS 7 basic network configuration
“ifconfig ens33 up”重新激活网卡ens33
Linux CentOS 7 basic network configuration

4、使用命令route添加、删除静态路由记录
“route add -net 192.168.100.0/24 gw 192.168.131.1”添加路由条目
“route del -net 192.168.100.0/24 ”删除路由条目
Linux CentOS 7 basic network configuration

5、使用命令route添加、删除默认网关记录
“route add default gw 192.168.131.1”添加默认网关
“route del default gw 192.168.131.1”删除默认网关
Linux CentOS 7 basic network configuration

四、配置双网卡
首先在主机中添加一块新的网卡并将两块网卡的状态都改为仅主机模式。
Linux CentOS 7 basic network configuration

此时我们使用“ifconfig”可以看到已经添加了一块新的网卡ens37,但两块网卡都没有IP地址,所以我们要对两块网卡进行IP地址的配置。
Linux CentOS 7 basic network configuration

首先我们进入配置文件对ens33网卡进行配置。
Linux CentOS 7 basic network configuration
Linux CentOS 7 basic network configuration

对网络服务进行重启,使网卡ens33生效。
Linux CentOS 7 basic network configuration

我们进入到网络配置文件中并没有发现ens37网卡。
Linux CentOS 7 basic network configuration

没有ens37我们可以复制一份ens33保存为ens37。
Linux CentOS 7 basic network configuration

但此时我们的ens37还不能立马使用,因为他的配置文件还是ens33的,我们还需要对其配置文件进行一定的修改。
Linux CentOS 7 basic network configuration

修改完成后对网络服务进行重启。
Linux CentOS 7 basic network configuration

这时我们的两块网卡就都配置好了。
Linux CentOS 7 basic network configuration

五、修改网络配置文件
1、主机名称配置文件
CentOS 6中修改系统的主机名,可以修改配置文件/etc/sysconfig/network。CentOS 7修改主机名则要修改的配置文件为/etc/hostname。
Linux CentOS 7 basic network configuration

2、域名解析配置文件
/etc/resolv.conf文件记录了本机默认使用的DNS服务器的地址信息,对该文件所做的修改会立即生效。
Linux CentOS 7 basic network configuration

3, the local host mapping file
when accessing an unfamiliar domain name first looks if the file has a corresponding record, if not, then go to the DNS server queries. hosts file to reduce the DNS query process, thereby increasing the network speed.
Linux CentOS 7 basic network configuration

Extracurricular Development: Remote File Synchronization

The native file server to another remote synchronization, format: scp local file path of the user @ip: remote server file path
First we see the hosts file to another server to facilitate comparison we sync.
Linux CentOS 7 basic network configuration

The native hosts file synchronization to another server. "Scp / etc / hosts [email protected]: / etc / hosts" → "yes" → remote server password
Linux CentOS 7 basic network configuration

View another server mapping file to verify synchronization results.
Linux CentOS 7 basic network configuration

The remote file server synchronized to the local. Format: scp user @ip: synchronous remote server file path of the local file path
to differentiate and convenient results show, first of all we add a new entry in the hosts another server.
Linux CentOS 7 basic network configuration

The remote server to the local file synchronization. "Scp [email protected]: / etc / hosts / etc / hosts" → remote server password is.
Linux CentOS 7 basic network configuration

Check your phone hosts file synchronization to verify the results.
Linux CentOS 7 basic network configuration

Guess you like

Origin blog.51cto.com/14449528/2434450