knowledge structure:
View network settings
Testing Network Connectivity
Use network configuration commands
Modify the network configuration file
(A) to view the network settings
1, view network interface information ifconfig
View all active network interfaces
Ifconfig command is executed
Check specify the network interface information
ifconfig network interface number
2, view the host name hostname
hostname command
View or set the current host name (temporary modification)
hostname or systemctl set-hostname zhangsan
3, check the routing table entry route
route command
View or set the host routing table information
route [-n] or direct route
4, check the network connectivity netstat
netstat command
View the status of the network connection system, routing tables, interface statistics and other information
netstat [options]
Common options
-a: List all
-n: Digital Representation
-p: Agreement
-t: lists tcp connection protocol
-u: list udp protocol connection
-r: lists the routing table information
netstat -ntap View the tcp protocol interface information
netstat -nuap View udp protocol information
netstat -r to see the routing table information like route
(Ii) test the network connection
ping command
Testing Network Connectivity
ping [options] target host
Tracking data packets traceroute
traceroute command
Test network node passes between the host and the destination from the current
traceroute destination host address
DNS nslookup
nslookup command
Test DNS name resolution
nslookup target host address [DNS Server Address]
(C) setting network parameters manner
Temporary Configuration - to adjust the network parameters using the command
Simple, fast, can directly modify the operation of the network parameters
Generally only suitable for use in the process of debugging the network
After a system reboot, your changes will fail
Fixed - to modify the network configuration file parameters
Modify the configuration file of the network parameters
Suitable for use when fixed parameter settings server
Network services need to reload or restart to take effect later
1, a network interface parameters ifconfig
Setting the network interface IP address, subnet mask (temporary settings)
ifconfig 接口号 ip地址 [netmask 子网掩码] ifconfig 网络接口 ip地址[/掩码长度]
禁用或者重新激活网卡
ifconfig 网路接口 up ifconfig 网络接口 down
设置虚拟网络接口(不同ip公用一个网卡)
ifconfig 接口号:序号 IP地址
2,设置路由记录route
添加到指定网段的路由记录
route add -net 网段地址 gw IP地址
删除到指定网段的路由记录
route del -net 网段地址
删除路由表中的默认网关记录
route del default gw IP地址
向路由表中添加默认网关记录
route add default gw IP地址
(四)修改网络配置文件(固定设置)
网络接口配置文件
/etc/sysconfig/network-scripts/目录下
启用,禁用网络接口配置
systemctl restart network
禁用,启用网络接口
ifdown ens33 ifup ens33
域名解析配置文件
/etc/resolv.conf文件
保存本机需要使用的DNS服务器的IP地址
[root@localhost ~]# vim /etc/resolv.conf 配置域名解析文件
主机名称配置文件
/etc/sysconfig/network文件
保存全局网络设置,只要包括主机名信息
[root@localhost ~]# vim /etc/sysconfig/network 配置主机名文件
本地主机映射文件
/etc/hosts文件
保存主机名与IP地址的映射记录
hosts文件和DNS服务器的比较
默认情况下,系统首先从hosts文件查找解析记录
hosts文件只对当前的主机有效
hosts文件可减少DNS查询过程,从而加快访问速度
[root@localhost ~]# vim /etc/hosts 配置当前主机的DNS解析
实验一
双网卡的配置(代理服务器功能,路由器,不同网卡配置不同的网段)
实验环境:
在虚拟机上配置两个网卡,并且将连接方式更改为仅主机相连,如何配置另一个网卡的信息
1,安装好两个网卡之后进主机相连之后用ifconfig查看两个网卡信息
2,先配置ens33的网卡信息,然后重启网卡即可生效
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]# service network restart 重启你的网卡服务,查看ens33网卡信息生效
3,因为/etc/sysconfig/network-scripts/下没有另一个网卡ens36的配置文件,所以要复制一份配置文件,然后修改配置信息
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36 复制当前目录下的ens33配置文件到当前目录下为ens36
[root@localhost network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-ens36 配置ens36网卡信息 [root@localhost ~]# service network restart 重启你的网卡服务,查看ens36网卡信息生效
双网卡配置不同网段就成功了
实验二
用SCP远程复制文件将一台主机的hosts文件复制到另一台主机hosts中使用DNS解析
环境:一台主机主机A(192.168.109.133)另一台主机B(192.168.109.132)
1,把本地文件同步到其他服务器
scp 本地同步文件路径 用户@ip:远程服务器文件路径
[Root @ localhost ~] # scp / etc / hosts [email protected]: / etc / hosts on the local synchronization to other servers
2, the other to a local server file synchronization
scp user @ip: synchronous remote server file path of the local file path
[Root @ localhost ~] # scp [email protected]: / etc / hosts / etc / hosts file to the other server synchronized to the local
thanks for reading! ! !