网络基础命令
[root@localhost sysconfig]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.88.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 #DHCP服务器及submask
0.0.0.0 192.168.88.2 0.0.0.0 UG 0 0 0 eth0 #网关,DNSserver
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.88.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.88.2 0.0.0.0 UG 0 0 0 eth0
Flags标志说明:
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Reinstate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
[root@localhost sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:D0:52:CC"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="2ea6c705-ac16-4ef5-8185-52d8ab5f9569"
[root@www.ctohome.com]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82567V-2 Gigabit Network Connection
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:1c:c0:f8:a1:ac
ONBOOT=yes
NETMASK=255.255.255.248
IPADDR=184.82.152.98
GATEWAY=184.82.152.97
TYPE=Ethernet
修改hostnmae
[root@localhost profiles]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
traceroute baidu.com #第一行就是自己的网关
[root@localhost network-scripts]# ip route show
192.168.88.0/24 dev eth0 proto kernel scope link src 192.168.88.133 metric 1
default via 192.168.88.2 dev eth0 proto static
说明:
# 192.168.88.133:本地IP
# 192.168.88.0/24:网段
# 192.168.88.2:网关
安装nslookup,以及dig工具(dig一般默认被安装,nslookup则没有,Windows下默认提供)
yum provides */nslookup
yum install bind-utils
域名解析基础配置文件:
ifconfig -a:查看ip/netmask
/etc/hosts :记录hostname对应的ip地址
/etc/resolv.conf :设置DNS服务器的ip地址
[root@localhost sysconfig]# cat /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.88.2
/etc/host.conf :域名解析配置文件(Resolver configuration file)
DNS的查询指令:host、nslookup、dig
host 语法:
Host [-a] [FQDN] [server]
Host -l [domain] [server]
参数说明:
-a :asking host to make a query of type ANY
-C :display the SOA records for zone name from all the listed authoritative name servers for that zone.
-t :CNAME, NS, SOA, SIG, KEY, AXFR, etc.By default, it looks for A, AAAA, and MX records, but if the -C option was given, queries will be made for SOA records,
-l :若后面接的那个domain设定允许allow-transfer时,则列出该domain所管理的所有主机名称对应资料。
Server: 这个参数可有可无,当想要利用非/etc/resolv.conf内的主机来查询主机名称与ip的对应时,就可以利用这个参数了。
[root@localhost network-scripts]# host -a qq.com
Trying "qq.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18171
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;qq.com. IN ANY
;; ANSWER SECTION:
qq.com. 5 IN A 61.135.157.156
qq.com. 5 IN A 125.39.240.113
qq.com. 5 IN MX 30 mx1.qq.com.
qq.com. 5 IN MX 10 mx3.qq.com.
qq.com. 5 IN MX 20 mx2.qq.com.
;; ADDITIONAL SECTION:
mx1.qq.com. 5 IN A 103.7.30.40
Received 132 bytes from 192.168.88.2#53 in 23 ms
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# host -l qq.com
; Transfer failed.
Host qq.com.localdomain not found: 4(NOTIMP)
; Transfer failed.
[root@localhost ~]# host -t any qq.com
qq.com has address 61.135.157.156
qq.com has address 125.39.240.113
qq.com name server ns1.qq.com.
qq.com name server ns2.qq.com.
qq.com name server ns3.qq.com.
qq.com name server ns4.qq.com.
qq.com has SOA record ns1.qq.com. webmaster.qq.com. 1350444472 300 600 86400 300
qq.com mail is handled by 20 mx2.qq.com.
qq.com mail is handled by 30 mx1.qq.com.
qq.com mail is handled by 10 mx3.qq.com.
nslookup和windows下的nslookup使用方法很像。
Nslookup [FQDN] [server]
nslookup -type=any qq.com
nslookup -query=mx qq.com
或者
nslookup #进入nslookup命令
然后set q=mx OR set type=mx
set q=a,mx,ptr,etc.
dig
Dig [@server] [FQDN] [type]
参数说明:
@server :如果不想以/etc/resolv.conf来作为dns主机,则可以在此填入其他的ip
Type :预设是查询A记录,你可以在这里写入其他的记录,如:MX,NS等。
此功能亦可使用[-t type]来处理。
下面是 dig 的一些比较常用的命令:
dig qq.com A
dig qq.com MX
dig -x 210.176.50.140 @8.8.8.8
dig baidu.com +nssearch # 查找一个域的授权 dns 服务器
dig bandainamcoasia.com +trace # 从根服务器开始追踪一个域名的解析过程
dig +norec @F.ROOT-SERVERS.NET HOSTNAME.BIND CHAOS TXT # 查看你使用的是那个 F root dns server