Linux network
1. Network configuration commands
1.1ifconfig
ifconfig 具体网卡名称 #只显示具体网卡的详细信息(无论该网卡是否使用)
ifconfig -a #表示显示所有网卡包括没有启动的网卡
ifconfig 网卡名称 [up|down] #表示开启或关闭网卡
ifconfig ens33:0 192.168.91.200设置虚拟网卡
ifconfig ens33:0查看虚拟网卡的详细信息
关闭虚拟网卡 ifconfig ens33:0 down
#网络通讯情况 ifconfig -s
配置网卡信息的命令:vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
#接口类型
BOOTPROTO=static
#地址获取方式 手动配置 dhcp 动态获取
NAME=ens37
#网卡名称
DEVICE=ens37
#网卡
ONBOOT=yes
#开机是否自启 开启
IPADDR=192.168.190.100
#地址
NETMASK=255.255.255.0
#子网掩码
GATEWAY=192.168.190.2
#网关
DNS1=8.8.8.8
#将ip地址转换成 域名
1.2 hostname
查看或设置当前主机名 hostname [主机名] //此为临时修改,关机后并不会保存
通过修改/etc/hostname文件来修改主机名
[root@localhost ~]# vim /etc/hostname
#永久生效
通过hostnamectl来修改主机名[root@localhost ~]# hostnamectl set-hostname www
[root@localhost ~]# bash
[root@www ~]# hostname
www.bdqn.com
#永久生效
1.3route
查看或设置主机中路由表信息
route -n
#The main components of the routing table are:
- #Destination: Destination network ID, indicating the reachable destination network ID, 0.0.0.0/0 represents all unknown networks, also known as the default route, with the lowest priority
- #Genmask: netmask corresponding to the target network
- #Iface: When reaching the corresponding network, which network card of the current host should send it out?
- #Gateway: Reach the non-directly connected network and send the data to the IP address of the interface adjacent to the host on the adjacent (next) router. If it is a directly connected network, the gateway is 0.0.0.0
- #Metric: Cost, the smaller the value, the highest priority of routing records
添加 指定网段的路由记录
route add -net network segment address gw IP address
删除指定网段的路由记录
route del -net network segment address
向路由表中添加默认网关记录
route add default gw IP address
删除路由表中默认的网关记录
route del default gw IP address
2. Management port
2.1netstat:
Port scan to see if the port is working properly
常用格式netstat -antp表示显示所有端口以数字方式tcp连接相关的进程信息
netstat选项:
a所有信息
n以数字方式显示信息
r显示路由表信息
l显示处于监听状态,网络连接和端口信息(监听状态标识建立通信端到端可以通信)
t显示tcp协议
u显示udp协议
p显示与网络链接相关的进程号,进程名称信息(必须有root权限)
netstat -antp | grep tcp View information about tcp
2.2ss
Obtain the communication socket and socket information. The usage is basically the same as netstat
ss option:
a所有信息
n以数字方式显示信息
r显示路由表信息
l显示处于监听状态,网络连接和端口信息(监听状态标识建立通信端到端可以通信)
t显示tcp协议
u显示udp协议
p显示与网络链接相关的进程号,进程名称信息(必须有root权限)
x表示内核相关
Commonly used commands ss -antp
ss -antp |grep ssh specifies searching for ssh related information
2.3 The difference between netstat and ss
- 1.ss is faster than netstat
- 2. In scenarios where ss uses a large connection, netstat may freeze.
3. Network communication
ping:在linux表示长ping,会一直ping,window是默认5次
ping -c+数字 表示指定次数
ping -W表示等待响应时间,等待之后继续ping
ping -w表示等待超时时间,超时之后不再继续ping
4、traceroute
测试当前主机到目的主机网络节点
traceroute查看路径(类似window的tracert命令)
The tracert command
traceroute 8.8.8.8 of the window can see that there are thirty points.
5. Application of DHCP in real-life scenarios
将虚拟机A作为DHCP服务器,给另一台虚拟机B分配地址,使虚拟机B能够正常联网
First turn off the local DHCP service of the virtual machine
第二步,在主机A上采用yum安装DHCP
第三步查看DHCP安装的详细信息
第四步,进入DHCP安装的配置信息文件中
第五步,进入该文件后,显示当前路径下的文件配置信息存放于 /user/share/doc/dhcp*/dhcp.conf.example中
第六步,将/user/share/doc/dhcp*/dhcp.conf.example下的配置文件信息拷贝到 /etc/dhcp/dhcpd.conf/中
第七步,进入/etc/dhcp/dhcpd.conf中,更改其配置文件
第八步 ,重新启动DHCP
第九步,查看dhcp使用的端口是否打开
最后一步,打开一台新的pc,发现其能通过刚才设置的DHCP连通网络。
6. Achieve time synchronization in simulated intranet environment
yum -y install chrony //安装chrony
rpm -qc chrony //查看chrony配置文件所在位置
vim /etc/chrony.conf //进入配置信息文件