route,ifconfig,netstat
网卡查看与设置
网卡命令:
ifconfig 接口名 IP/掩码 up/down
-a 显示所有网卡
ifconfig eth0 直接显示某个网卡信息
ifconfig eth0 IP/MASK 配置网卡
ifconfig eth0 up 启用网卡,ifup eth0
ifconfig eth0 down 禁用网卡,ifdown eth0
ifconfig eth0 192.168.98.128/24 配置网卡
ifconfig eth0 192.168.96.128/24 up 设置或添加并启用网卡
ifconfig eth0 192.168.96.128 netmask 255.255.255.0
启用混杂模式:promisc,-promisc,加减号表示禁用
ifconfig eth0 192.168.96.130 netmask 255.255.255.0 broadcast 192.168.96.255 up broadcast为广播地址
添加多网卡:
ifconfig ens33:0 192.168.96.138/24 up
启动网卡:
RH5 /etc/init.d/network start | stop | restart | status
RH6 /etc/init.d/NetworkManager
service network start
配置文件:
/etc/sysconfig/network-scripts/ifcfg-ethX
路由管理与设置
查看:
route -n
配置文件:/etc/sysconfig/network
添加:
route add [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
添加主机路由:
route add -host 192.168.1.3 gw 172.16.0.1 dev eth0 这里的主机地址为192.168.1.3,主机路由的子网掩码是32位,默认自动识别可以不填。
添加网络路由:
route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0
route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.1
添加默认路由:
route add default gw 192.168.96.2
route add -net 0.0.0.0/0 gw 192.168.96.2
上面的两种方法点都可以,添加后的路由条目如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.96.2 0.0.0.0 UG 0 0 0 ens33
这里的目标地址为0.0.0.0表示任意网络,网关为192.168.96.2,表示到达任意网络的网关是192.168.96.2。在Flags条目下一班会有UG或UGH,U表示up启用,G表示gateway,H表示host意为主机路由,没有H则表示主机路由。
删除路由:
route del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If]
删除主机路由:
route del -host 192.168.1.3
删除网络路由:
route del -net 192.168.0.0 netmask 255.255.255.0
删除默认路由:
route del default gw 192.168.96.2
注意:使用route命令设置的都是临时的
netstat命令
显示网络连接:
netstat
-t tcp协议相关
-u udp协议相关
-w raw socket相关
-l 处于监听状态
-a 所有状态
-n 以数字显示IP和端口;
-e 扩展格式
-p 显示相关进程及PID
常用组合:-tan, -uan, -tnl, -unl
显示路由表:netstat {--route|-r} [--numeric|-n]
-r 显示内核路由表
-n 数字格式
显示接口统计数据:
netstat {--interfaces|-I|-i} [iface] [--all|-a] [--extend|-e] [--program|-p] [--numeric|-n]
netstat -i 显示所有接口
netstat -Ieth0 大写的 i 后面不加空格
ping命令:
ping -s 65507 -f IP