ping

ping 将数据包发向用户指定地址。当包被接收,目标机器发送返回数据包。ping 主要有两个作用:

用来确认网络连接是畅通的。
用来查看连接的速度信息。
-c 参数可以定义 ping 的次数 ping www.hqq365.com -c6
windows -n 代表次数 ping www.hqq365.com -n 6

ifconfig

查看用户网络配置。它显示当前网络设备配置。对于需要接收或者发送数据错误查找,这个工具极为好用
ifconfig eth0 mtu 1500
//设置能通过的最大数据包大小为 1500 bytes
ifconfig eth0 192.168.1.56 netmask 255.255.255.0
// 给eth0网卡配置IP地址,并加上子掩码
ifconfig eth0 up //启动网卡

nslookup

查询DNS的记录,查看域名解析是否正常,在网络故障的时候用来诊断网络问题。 默认没有这个软件需要安装,yum provides nslookup 查询是哪一下安装包 yum install bind-utils
例:nslookup www.hqq365.com

[root@skyhu ~]# nslookup www.hqq365.com
Server:         183.60.83.19
Address:        183.60.83.19#53

Non-authoritative answer:
Name:   www.hqq365.com
Address: 211.159.225.160

traceroute

可用来查看数据包在提交到远程系统或者网站时候所经过的路由器的 IP 地址、跳数和响应时间。
traceroute www.hqq365.com
windows命令
tracert hostname

telnet

通过 telnet 协议连接目标主机,如果 telnet 连接可以在任一端口上完成即代表着两台主机间的连接良好。
使用指定的端口 telnet 主机名。这通常用来测试主机是否在线或者网络是否正常。
telnet hostname port // telnet hqq365.com 22

ethtool

用于查询及设置网卡参数的命令

ethtool ethx //查询ethx网口基本设置,其中 x 是对应网卡的编号,如eth0、eth1等等
ethtool –h //显示ethtool的命令帮助(help)
ethtool –i ethX //查询ethX网口的相关信息
ethtool –d ethX //查询ethX网口注册性信息
ethtool –r ethX //重置ethX网口到自适应模式
ethtool –S ethX //查询ethX网口收发包统计
ethtool –s ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off] //设置网口速率10/100/1000M、设置网口半/全双工、设置网口是否自协商 ethtool -s eth0 speed 1000 duplex full autoneg off
效果:将设备号eth0对应的物理端口设置为速率为1000Mbps,全双工工作模式,同时关闭自动协商。
注:若需要永久更改有两种方法:1. 将上述命令写入/etc/rc.local文件中,开机自动执行;2. 在/etc/sysconfig/network-scripts/ifcfg-eth0中添加一行ETHTOOL_OPTS="speed 1000 duplex full autoneg off"。这里仅仅以eth0为例,其他设备号同理。
查询网络端口位置ethtool -p
这个命令多用于管理多网口的服务器主机,由于背板的网络端口数量大,有时候不知道那个物理端口对应eth0或其他设备号,我们就可以使用这个命令来查询。
用法:ethtool -p eth0
效果:设备号eth0对应的物理端口的两个指示灯会闪烁

route

route命令用于查看或修改主机和网络的路由信息。
route // 显示路由信息。
route add --host 192.168.1.110 dev eth0  // 给网卡eth0的路由表中加入新地址192.168.1.110。
route add -p 172.22.0.0 mask 255.255.0.0 172.22.133.1 //windows加永久路由
route add default gw 192.168.0.1 // 给路由表中添加默认网关地址192.168.0.1
route add –net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 // 给子网192.168.1.0添加路由和网关,新增加的路由和网关地址为192.168.1.1。
route del –host 192.168.1.110 dev eth0 // 删除网卡eth0路由表中的地址192.168.1.110。
route del –net 192.168.1.0 netmask 255.255.255.0 // 在路由表中删除子网192.168.1.0的路由信息。
route change 192.168.1.0 mask 255.255.255.0 192.168.10.100 // 将子网 192.168.1.0 的下一跃点地址设置为 192.168.10.100。

配置文件增加IPV4_ROUTE_METRIC=90 修改路由优先级

netstat

netstat命令用于显示本机上与IP、TCP、UDP和ICMP协议相关的统计数据,该命令经常被用于检验本机各端口的网络连接情况。
netstat -nap | grep port 将会显示使用该端口的应用程序的进程 id

netstat -a or netstat –all 将会显示包括 TCP 和 UDP 的所有连接

netstat –tcp or netstat –t 将会显示 TCP 连接

netstat –udp or netstat –u 将会显示 UDP 连接
netstat –r // 显示路由表
-t:列出TCP协议的端口

-u:列出UDP协议的端口

-n:显示IP地址和端口号,而不显示域名和服务名

-l:仅列出处于监听Listening状态的端口

-a:列出所有网络连接

修改成固定IP

BOOTPROTO="none"
IPADDR=10.0.1.204
GATEWAY=10.0.1.2
DNS1=8.8.8.8

查看 IP 地址和数据统计

ifconfig 版本:

ifconfig:显示 up 状态的端口信息,包括 ip、mac、统计等。
ifconfig -a:显示所有状态的端口信息,包括 ip、mac、统计等。

ip 版本:

ip addr(简写成 ip a):显示所有端口信息,包括 ip、mac、up/down 等。
ip -4 a:仅显示带 ipv4 地址的端口信息。
ip -s link:显示所有端口统计信息。
ip -s link ls eth0:显示 eth0 端口的统计信息。
ip -s -s link ls eth0:更详细地显示 error 信息。

添加/删除端口的 ip 地址

ifconfig 版本:

ifconfig eth0 192.168.120.56 netmask 255.255.255.0:临时添加 eth0 的 ip 地址。

ip版本:

ip addr add 192.168.2.199/24 dev eth0:临时添加 eth0 的 ip 地址。
ip addr del 192.168.2.199/24 dev eth0:删除 eth0 的 ip 地址。

UP/DOWN 端口

ifconfig 版本:

ifconfig eth0 up:将端口 eth0 启动。
ifconfig eth0 down:将端口 eth0 关闭。

ifup/ifdown 版本:

ifup ifcfg-eth0:将端口 eth0 启动。
ifdown ifcfg-eth0:将端口 eth0 关闭。

ip 版本:

ip link set dev eth0 up:将端口 eth0 启动(无需 ifcfg-eth0 文件存在)。
ip link set dev eth0 down:将端口 eth0 启动(无需 ifcfg-eth0 文件存在)。

路由配置

route 版本:

route -n:查看路由信息
route add default gw 192.168.1.1 eth0:添加默认网关路由
route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0:添加到网络的路由
route add -host 10.20.30.148 gw 10.20.30.40:添加到主机的路由

ip 版本:

ip route:查看路由信息
ip route add default via 192.168.1.1:添加默认网关路由
ip route add 192.168.0.0/24 via 192.168.1.2:添加到网络的路由
ip route add 192.168.1.3 via 172.16.0.1 dev eth0:添加到主机的路由

标签: none

添加新评论