1、使用ifconfig命令查看网络接口地址
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //第一块以太网卡的名称
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::1749:6c57:bf18:59fb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:79:01:01 txqueuelen 1000 (Ethernet)
RX packets 113805 bytes 168591346 (160.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27171 bytes 1694071 (1.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 //“回环“网络接口
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 96 bytes 8288 (8.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 8288 (8.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 //虚拟网桥的连接接口
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:89:87:fd txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看指定的网络接口信息
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::1749:6c57:bf18:59fb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:79:01:01 txqueuelen 1000 (Ethernet)
RX packets 114041 bytes 168643166 (160.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27198 bytes 1697300 (1.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、使用hostname命令查看主机名称
[root@localhost ~]# hostname
localhost.localdomain
3、使用route命令查看路由表条目
[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.1.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
4、使用netstat命令查看网络连接情况
[root@localhost ~]# netstat -anot | grep 53
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN off (0.00/0/0)
参数 | 说明 | 参数 | 说明 |
---|---|---|---|
-a | 显示当前主机中所有活动的网络连接信息 | -n | 以数字的形式显示相关的主机地址、端口等信息 |
-r | 显示路由表信息 | -I | 显示处于监听(Listening)状态的网络连接及端口信息 |
-t | 查看TCP相关的信息 | -u | 显示UDP协议相关的信息 |
-P | 显示与网络连接相关联的进程号、进程名称信息 |
1、使用ping命令测试网络连通性
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=128 time=29.4 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=128 time=24.1 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=128 time=23.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=128 time=22.4 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=128 time=20.7 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 20.778/24.153/29.408/2.898 ms
2、使用traceroute命令跟踪数据包的路由途径
[root@localhost ~]# traceroute www.baidu.com
traceroute to www.baidu.com (39.156.66.14), 30 hops max, 60 byte packets
1 gateway (192.168.1.1) 0.135 ms 0.073 ms 0.097 ms
2 * * *
3 * * *
3、使用nslookup命令测试DNS域名解析
[root@localhost ~]# nslookup www.163.com
Server: 223.5.5.5
Address: 223.5.5.5#53
Non-authoritative answer:
www.163.com canonical name = www.163.com.163jiasu.com.
www.163.com.163jiasu.com canonical name = www.163.com.lxdns.com.
Name: www.163.com.lxdns.com
Address: 183.201.203.129
1、使用ifconfig命令修改网卡的地址、状态
(1)将网卡ens33的IP地址设置为192.168.1.168,子网掩码长度为24
[root@localhost ~]# ifconfig ens33 192.168.1.168/24
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:75:ac:c4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.168/24 brd 192.168.1.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::f1bd:1336:2662:4e77/64 scope link
valid_lft forever preferred_lft forever
inet6 fe80::1749:6c57:bf18:59fb/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
(2)禁用、激活网络接口(“down"和"up”)
[root@localhost ~]# ifconfig ens37 down //禁用ens37网卡
(3)为网卡绑定虚拟接口
[root@localhost ~]# ifconfig ens33:0 172.17.17.17
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.168 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::f1bd:1336:2662:4e77 prefixlen 64 scopeid 0x20<link>
inet6 fe80::1749:6c57:bf18:59fb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:75:ac:c4 txqueuelen 1000 (Ethernet)
RX packets 28310 bytes 41584089 (39.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7259 bytes 484554 (473.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.17.17 netmask 255.255.0.0 broadcast 172.17.255.255
ether 00:0c:29:75:ac:c4 txqueuelen 1000 (Ethernet)
2、使用route命令添加、删除静态路由记录
(1)添加、删除到指定网段的路由记录
[root@localhost ~]# route add -net 192.168.3.0/24 gw 192.168.4.254 //添加静态路由
[root@localhost ~]# route del -net 192.168.3.0/24 //删除静态路由
(2)添加、删除默认网关记录
[root@localhost ~]# route -n | grep "192.168.4.1" //查看原路由表中的默认网关记录
[root@localhost ~]# route del default gw 192.168.4.1 //删除默认网关记录
[root@localhost ~]# route add default gw 192.168.4.254 //添加新的默认网关记录192.168.4.254
3、使用hostname命令修改主机的名称
[root@localhost ~]# hostname www.CSDN.com //将主机名改为"www.CSDN.com"
[root@localhost ~]# bash
[root@www ~]# hostname
www.CSDN.com
1、网络接口配置文件
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet //设置网卡类型,"Ethernet"表示以太网
BOOTPROTO=static //设置网络接口的配置方式。"static"时表示使用静态指定的IP地址,为"dhcp"时表示通过DHCP的方式动态获取地址
IPADDR=192.168.1.10 //设置网络接口的IP地址
GATEWAY=192.168.1.1 //设置网络接口的默认网关地址
NETMASK=255.255.255.0 //设置网络接口的子网掩码
DNS1=223.5.5.5
DNS2=114.114.114.114
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=79bb435d-aa99-4f58-9e6e-b44599e60039
DEVICE=ens33 //设置网络接口的名称
ONBOOT=yes //设置网络接口是否在Linux操作系统启动时激活
2、启用、禁用网络接口配置
重启network服务
[root@localhost ~]# systemctl restart network
先关闭ens33网卡,然后根据配置文件启用ens33网卡
[root@localhost ~]# ifdown ens33
成功断开设备 'ens33'。
[root@localhost ~]# ifup ens33
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/4)
3、主机名称配置文件
[root@localhost ~]# vim /etc/hostname
localhost.localdomain
或者
[root@localhost ~]# vim /etc/sysconfig/network
networking=yes
hostname=www.CSDN.com
4、域名解析配置文件
(1)指定为本机提供DNS解析的服务器地址
指定默认使用的两个DNS服务器地址分别位于202.106.0.20 和 202.106.148.1
[root@localhost ~]# vim /etc/resolv.conf
search localdomain
nameserver 202.106.0.20
nameserver 202.106.148.1
(2)本地主机映射文件
查找是否有相应的映射记录
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
1、安装DHCP服务器软件
[root@localhost ~]# yum -y install dhcp
2、建立主配置文件dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf(可直接创建)
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 { //声明192.168.1.0网段
range 192.168.1.100 192.168.1.200; //地址池
option domain-name-servers 202.106.0.20,202.106.148.1; //DNS服务器地址
option routers 192.168.1.1; //默认网关
default-lease-time 600; //默认租约,可以省略
max-lease-time 7200; //最大租约,可以省略
#option domain-name "admin.com"; //默认搜索区域
#ddns-update-style none //动态DNS更新模式
}
host localhost.localdomain { //声明保留地址
hardware ethernet 00:0c:29:75:ac:c4; //客户端的MAC地址
fixed-address 192.168.1.150; //保留的IP地址
}
[root@localhost ~]# systemctl restart dhcpd
3、排错
[root@localhost ~]# tail -30 /var/log/messages
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=dhcp
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# ifdown ens33 ; ifup ens33
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/5)
[root@localhost ~]# dhclient -d ens33
Internet Systems Consortium DHCP Client 4.2.5
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens33/00:0c:29:75:ac:c4
Sending on LPF/ens33/00:0c:29:75:ac:c4
Sending on Socket/fallback
DHCPREQUEST on ens33 to 255.255.255.255 port 67 (xid=0x5b07f9b5)
DHCPREQUEST on ens33 to 255.255.255.255 port 67 (xid=0x5b07f9b5)
DHCPDISCOVER on ens33 to 255.255.255.255 port 67 interval 7 (xid=0x48df23e5) //DHCP发现
DHCPREQUEST on ens33 to 255.255.255.255 port 67 (xid=0x48df23e5) //DHCP请求
DHCPOFFER from 192.168.1.10 //DHCP提供
DHCPACK from 192.168.1.10 (xid=0x48df23e5) //DHCP确认
bound to 192.168.1.150 -- renewal in 267 seconds.
释放获取的IP租约
[root@localhost ~]# dhclient -r ens33
1、系统时间
[root@localhost ~]# date //查看当前时间
2020年 06月 26日 星期五 16:18:08 CST
[root@localhost ~]# ntpdate ntp1.aliyun.com //时间同步
26 Jun 16:18:32 ntpdate[50701]: adjust time server 120.25.115.20 offset -0.003190 sec
2、硬件时间
[root@localhost ~]# hwclock -r //读出BIOS的时间参数
2020年06月26日 星期五 16时21分30秒 -0.037898 秒
[root@localhost ~]# hwclock -w //将当前系统时间写入BIOS中