linux网络属性配置(2)
ifcfg命令家族:ifconfig,route,netstat
\
ifconfig命令:接口及地址查看及管理
ifconfig [INTERFACE]
# ifconfig -a :显示所有接口,包括未激活的
ifconfig interface [aftype] options |address ... 则是用来配置的
# ifconfig IFACE(接口名称) IP/MASK [up] 打开
#ifconfig IFACE IP netmask NETMASK
options:
[-]promisc 混杂模式
注意:立即送往内核中的TCP/IP协议栈,并生效
管理IPv6地址:
add addr/prefixlen
del addr/prefixlen
\
route命令:路由查看及管理
路由条目类型:
主机路由:目标地址为单个IP
网络路由:目标地址为IP网络
默认路由:目标为任意主机,0.0.0.0/0.0.0.0
查看:
route -n(不反解)
添加:
route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw(关键字) GW(下一跳地址)] [[dev] if]
示例:route add -net 10.0.0.0/8 gw 192.168.10.1 dev eth1
示例:route add -net 0.0.0.0/0.0.0.0 gw 192.168.10.1 (添加默认路由)
示例:route add -net default gw 192.168.10.1 (添加默认路由)
删除:
route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm]
例如:route del -net 10.0.0.0/8
route del default
netstst命令:
print network connect ,routing tables,interface statisics,masquerade ,masquerade connections,and multicast memberships(多播成员关系)
显示路由:netstat -n
-r|-- route:显示内核路由表
-n:数字格式
显示网络连接:
netstat [--tcp|-t] [--udp|-u] [--udplite]
传输层协议:
tcp:面向连接的协议;通讯开始前,要建立一个虚链路;通讯完成后还要拆除连接;tcp连接的相关信息(tcp被称为有连接的协议);像打电话
udp:无连接的协议;直接发送数据报文;(udp被称为用户数据报协议);像送信
ifconfig显示
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.211 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::29cf:27d2:3cd0:8ce2 prefixlen 64 scopeid 0x20<link>
ether 94:08:53:3c:38:9d txqueuelen 1000 (Ethernet)
RX packets 21767 bytes 24469430 (23.3 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 8978 bytes 1945036 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
<UP> | 意为网卡处于激活状态 |
<BROADCAST> | 支持广播 |
<MULTICAST> | 支持组播(多播) |
mtu 1500 | 网卡最大传输单元不超过1500字节 |
inet 172.168.3.211 | IP地址 |
netmask | 掩码 |
broadcast | 广播地址 |
主机号全为1的是广播地址,例如192.168.99.255
全为0为本机地址
inet6 fe80::29cf:27d2:3cd0:8ce2 | IP地址 |
ether 94:08:53:3c:38:9d | 以太网地址 |
txqueuelen 1000 | 传输队列长度 |
RX | 接受 |
TX | 传出 |
RX packets 21767 bytes 24469430 (23.3 MiB) | 网卡打开接受到的总报文数量为21767 |
bytes 24469430 (23.3 MiB) | 总大小为23.3MiB |
RX errors 0 dropped 1 overruns 0 frame 0 | 错误 掉包 溢出 帧 |
TX packets 8978 bytes 1945036 (1.8 MiB) | 传出 |
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | 错误 掉包… |
centos7与centos6版本跨越还是非常大的
ifconfig wlp3s0
ifconfig 默认是显示激活状态的
ifconfig -a 显示所有,包括非激活
ifconfig配置
1.打开接口
[syh@localhost ~]$ ifconfig virbr0-nic 192.168.10.100/24 up
SIOCSIFADDR: 不允许的操作
SIOCSIFFLAGS: 不允许的操作
SIOCSIFFLAGS: 不允许的操作
SIOCSIFNETMASK: 不允许的操作
[syh@localhost ~]$ ifconfig virbr0-nic 192.168.10.100/24 up
[syh@localhost ~]$ ifconfig virbr0-nic
virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.10.100 netmask 255.255.255.0 broadcast 192.168.10.255
ether 52:54:00:e0:87:cf 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
2.模式的启用
[syh@localhost ~]$ ifconfig virbr0-nic
virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.10.100 netmask 255.255.255.0 broadcast 192.168.10.255
ether 52:54:00:e0:87:cf 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
[syh@localhost ~]$ sudo ifconfig virbr0-nic promisc
[syh@localhost ~]$ ifconfig virbr0-nic
virbr0-nic: flags=4355<UP,BROADCAST,PROMISC,MULTICAST> mtu 1500
inet 192.168.10.100 netmask 255.255.255.0 broadcast 192.168.10.255
ether 52:54:00:e0:87:cf 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
多了PROMISC
[syh@localhost ~]$ sudo ifconfig virbr0-nic -promisc
关闭PROMISC
route显示
[syh@localhost ~]$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 600 0 0 wlp3s0
192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
destination | 目的地 |
gateway | 下一跳(有效地址的都是网关) |
genmask | 掩码地址 |
flags | |
metric | 度量值(中途的开销) |
ref | |
use | |
iface | 发送的网卡 |
route操作
[master ^_^:now in ~,time: 19:52,name:root]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.3.1 0.0.0.0 UG 600 0 0 wlp3s0
192.168.3.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[master ^_^:now in ~,time: 19:53,name:root]#route add -net 10.0.0.0/8 gw 192.168.3.1
[master ^_^:now in ~,time: 19:53,name:root]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.3.1 0.0.0.0 UG 600 0 0 wlp3s0
10.0.0.0 192.168.3.1 255.0.0.0 UG 0 0 0 wlp3s0
192.168.3.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[master ^_^:now in ~,time: 19:53,name:root]#
route add -net 10.0.0.0/8 gw 192.168.3.1
到达网络(掩码可另写) 下一跳(必须是同网段) dev可不写(会自动判断)
10.0.0.0不是默认网关因为不是默认路由