用命令修改的均为临时生效,重启后失效,要想永久生效需更改配置文件
设置主机名
vi etc/sysconfig/network
查看主机名
hostname
设置IP地址
ifconfig 网卡名 IP地址 netmask 子网掩码
ifconfig etho 10.0.0.1 netmask 255.0.0.0
查看某快网卡的状况
ifconfig 网卡名
ifconfig eth0
多IP设置
ifconfig 网卡名:虚拟网卡ID IP地址 netmask 子网掩码
ifconfig eth0:0 10.1.1.1 netmask 255.0.0.0
禁用和启用网卡
ifconfig 网卡名称 down 或 ifdown eth0
ifconfig 网卡名称 up 或 ifup eth0
临时修改MAC,重启后失效
ifdowm eth0
ifconfig eht0 hw ether 00:37:a6:c4:68:e3
ifup eth0
添加/删除默认网关
route add/del default gw IP地址
查看网管及路由
route
[root@localhost sysconfig]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.16.0 * 255.255.255.0 U 1 0 0 eth0
default 192.168.16.1 0.0.0.0 UG 0 0 0 eth0
U表示该条路由条目为活跃的,G表示该条路由条目要涉及到网关
网卡配置文件
cd /etc/sysconfig/network-scripts/
ls ifcfg-*
vi ifcfg-eth0
设置DNS
etc/resolv.conf
ping
-c ping的次数
-s 数据包的大小
icmp_seq 数据包的序号从1开始
ttl 生存周期
time 响应时间
netstat -ant
[root@localhost etc]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:40102 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.16.36:53755 63.146.70.75:80 ESTABLISHED
tcp 0 0 :::43139 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
-a 显示所有链接 -t显示TCP协议 -u可显示UDP协议 默认则都显示
state链接状态
LISTEN表示监听状态,等待接收入站的请求
ESTABLISHED表示本机已经与其他主机建立好链接
TIME_WAIT等待足够的时间以确保远程TCP接受到链接中断请求的确认
netstat -r 查看当前主机的路由表信息
netstat -i 监控主机网络接口的统计信息,显示数据包发送和接收情况
[root@localhost etc]# netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 40966 0 0 0 4833 0 0 0 BMRU
lo 16436 0 16 0 0 0 16 0 0 0 LRU
MTU表示最大传输单元,即网络接口传输数据包的最大值。Met为度量值,越小优先级越高。RX-OK/TX-OK分别表示接收、发送数据包的数量,RX-ERR/TX-ERR分别表示接收、发送错误数据包的数量,RX-DRP/TX-DRP为丢弃的数量,RX-OVR/TX-OVR表示丢失数据包数量。
nslookup
非交互模式仅仅可以查询主机和域名信息。
查询www.baidu.com对应的DNS信息
[root@localhost etc]# nslookup www.baidu.com
Server: 202.102.134.68
Address: 202.102.134.68#53
Non-authoritative answer:
Name: www.baidu.com
Address: 61.135.169.125
Name: www.baidu.com
Address: 61.135.169.105
将IP解析为主机名
[root@localhost etc]# nslookup 219.141.136.10
Server: 202.102.134.68
Address: 202.102.134.68#53
Non-authoritative answer:
10.136.141.219.in-addr.arpa name = xd-cache-1.bjtelecom.net.
Authoritative answers can be found from:
136.141.219.in-addr.arpa nameserver = xd-dns.bjtelecom.net.
xd-dns.bjtelecom.net internet address = 219.141.148.19
交互模式
[root@localhost etc]# nslookup
> ^C[root@localhost etc]#
[root@localhost etc]# nslookup
> www.redhat.com
Server: 202.102.134.68
Address: 202.102.134.68#53
Non-authoritative answer:
Name: www.redhat.com
Address: 218.58.101.214
> 61.135.169.105
Server: 202.102.134.68
Address: 202.102.134.68#53