1.查看即测试网络
1.查看网络接口地址
查看活动网络接口——ifconfig
查看活动网络接口——ifconfig ens33
2.查看主机名称hostname
[root@localhost ~]# hostname
localhost.localdomain
3.查看路由表条目
[root@localhost ~]# route (查看路由条目)
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 100 0 0 ens33
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@localhost ~]# route -n (以数字的形式显示)
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.254 0.0.0.0 UG 100 0 0 ens33
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
备注:
Destination目标网段地址
Gateway 下一跳路由器地址
Iface 数据的网络接口
4.查看网络接口
(1)netstat
netstat可以查看网络连接状态,路由表,接口统计信息
选项:
- -a 显示所有接口信息
- -n 显示以数字形式显示
- -r 显示路由表信息
- -l 显示监听状态
- -t 显示TCP信息
- -p 显示进程号,进程名称
备注:通常与-anpt组合使用
[root@localhost ~]# netstat -anpt | grep sshd
(2)ss Socket Statistics缩写
选项:
- -h help 获取更多帮助
- -V version 软件版本
- -t 显示TCP协议
- -u 显示UDP协议
- -n numeric 不解析服务名称
- -l listening 显示监听端口状态
- -p processes 显示监听端口进程
- -a all 包含监听端口和建立连接
- -r resolve 把IP解释为域名,把端口解释为协议
[root@localhost ~]# ss -t state established
5.测试网络连接
可以使用ping命令,Ctrl+C终止命令
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data.
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=4 ttl=128 time=158 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=5 ttl=128 time=26.0 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=6 ttl=128 time=38.2 ms
6.跟踪数据包路由途径
使用trsceroute命令,可以使用yum安装trsceroute。tracerouteky具体显示当前主机到目的主机经过哪些接点和连接状态,无法响应用*表示。
[root@localhost ~]# traceroute www.baidu.com
traceroute to www.baidu.com (110.242.68.3), 30 hops max, 60 byte packets
1 gateway (192.168.10.254) 3.978 ms 3.710 ms 0.324 ms
2 * * *
7.测试DNS域名解析
(1)nslookup
nslooup用来测试域名解析,安装bind-utils。
[root@localhost ~]# yum -y install bind-utils
[root@localhost ~]# nslookup www.baidu.com
(2)dig
dig全称(domain information groper),与nslookup相比较,dig可以查询到更多的域名信息。
[root@localhost ~]# dig www.baidu.com
2.设置网络地址参数
1.修改网卡地址,状态
[root@localhost ~]# ifconfig ens33 192.168.10.101/24或者
[root@localhost ~]# ifconfig ens33 192.168.10.101 netmask 255.255.255.0
2.禁用,激活网络接口
[root@localhost ~]# ifconfig ens33 down (禁用)
[root@localhost ~]# ifconfig ens33 up (激活)
3.绑定虚拟接口
首先添加一个网络适配器
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
[root@localhost network-scripts]# ifconfig
[root@localhost network-scripts]# ifconfig ens36 10.0.0.1 (绑定虚拟接口,存在关机重启失效)
[root@localhost network-scripts]# ifconfig
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36 (将ens33的配置参数复制)
[root@localhost network-scripts]# vim ifcfg-ens36 (进行vim编辑器进行修改参数即可)
[root@localhost network-scripts]# systemctl restart network (重启计算机)
[root@localhost network-scripts]# ifconfig (经过查询可知ens36是192.168.10.102)
3.添加路由条目
(1)添加,删除指定网段路由
记录
[root@localhost ~]# route add -net 172.16.0.0/16 gw 192.168.10.200
[root@localhost ~]# route -n
备注:
172.16.0.0/16是目标网络
192.168.10.200 网关
[root@localhost ~]# route del -net 172.16.0.0/16 (删除该进程)
[root@localhost ~]# route -n (查询)
(2)添加,删除默认网关
[root@localhost ~]# route add default gw 192.168.10.254 (添加默认网关)
[root@localhost ~]# route -n
[root@localhost ~]# route del default gw 192.168.10.254 (删除默认网关)
[root@localhost ~]# route -n
4. 修改主机名称
(1)临时修改
[root@localhost ~]# hostname abc
[root@localhost ~]# bash
(2)永久修改
方法一:
[root@abc ~]# systemctl restart network
[root@abc ~]# vim /etc/hostname (vim编辑器进行命名)
方法二:
[root@abc ~]# hostnamectl set-hostname bbb
[root@abc ~]# bash
[root@bbb ~]# (修改成功)
5.域名解析配置文件
[root@localhost ~]# vi /etc/resolv.conf
search localdomain
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@localhost ~]# vim /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifcfg-rh (去掉前面#号)
dns=none ##在main区域添加此行
[root@localhost ~]# [root@manager ~]# systemctl restart NetworkManager