@[TOC]第一章 Linux 网络设置与基础服务
查看及测试网络
1.1 查看活动的网络接口设备
命令:ifconfig (不接限定内容,显示全部接口)
查看指定网络接口:ifconfig ens33
查询后显示内容,主要查看ether 网络的物理地址
inet 网络接口的IP地址
broadcast 网络接口所在的网络广播地址
netmask 子网掩码
2.1 查看路由表、接口统计
命令:netstat
-n 以数字形式查看
-a 所有
p 显示与网络连接相关联的进程号
t 查看tcp协议相关的信息
[root@localhost /]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.99.2 0.0.0.0 UG 100 0 0 ens33
192.168.99.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
3.1 ping 命令 测试网络连通性
4.1 追踪命令 traceroute
[root@localhost /]# traceroute www.baidu.com
traceroute to www.baidu.com (14.215.177.39), 30 hops max, 60 byte packets
1 gateway (192.168.99.2) 0.435 ms 0.231 ms 0.116 ms
2 * * *
3 * * *
5.1 nslookup 测试域名解析
[root@localhost /]# nslookup www.firefox.com
Server: 192.168.99.2
Address: 192.168.99.2#53
Non-authoritative answer:
www.firefox.com canonical name = firefox.com.
Name: firefox.com
Address: 63.245.208.212
网络配置命令
1、修改网卡的地址、状态ifconfig
修改网卡的地址、子网掩码
ifconfig ens33 192.168.99.129/24
ifconfig ens33 192.168.99.129 netmask 255.255.255.0
禁用、激活网络接口
ifconfig ens33 down ifconfig ens33 up
or ifdown ens33 ifup ens33
绑定虚拟接口
[root@localhost /]# ifconfig ens33:0 172.16.0.1
[root@localhost /]# ifconfig
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.0.1 netmask 255.255.0.0 broadcast 172.16.255.255
ether 00:0c:29:ea:44:c7 txqueuelen 1000 (Ethernet)
2、添加、删除静态路由
静态路由 使本机访问网段192.168.3.0/24 的数据包都发给192.168.2.22接口
route add -net 192.168.3.0/24 gw 192.168.2.22
删除
route del -net 192.168.3.0/24
默认路由 同一主机只应有一个默认路由
添加 route add default gw 192.168.2.22
删除 route del default gw 192.168.2.1
修改网络配置文件
网络接口配置文件
配置文件为:ifcfg-*** 网络接口名称
配置前先查询:ls /etc/sysconfig/network-scripts/
vim /etc/sysconfig/network-scripts/ens33
DEVICE:网络接口的名称
ONBOOT:设置为启动时激活
BOOTPROTO: 网络接口配置方式“static”或者“dhcp”
IPADDR: IP地址
NETMASK: 子网掩码
GATEWAY: 默认网关
DNS1: 域名解析
主机名称配置文件
vim /etc/hostname