网络设备, 网卡配置:
Eth0 是物理网卡: 唯一 mac 地址, Bcast: 广播地址, MAsk: 子网掩码,
Lo: 系统自带的回环的 ip 地址, 可以做一些基本的测试应用, 比如没有网卡就用 127.0.0.1,
- root@ubuntu:/# ifconfig ens33 down (停掉某个网卡, 重启操作系统可以起起来)
- root@ubuntu:/# ifconfig ens33 up (启动某个网卡)
- root@ubuntu:/# ifconfig ens33 192.168.115.129 (修改 ip 地址, 临时生效, 配置文件才能永久生效)
- root@ubuntu:/# ifconfig ens33 192.168.115.129 netmask 255.255.255.0 (修改子网掩码, 临时生效, 配置文件才能永久生效)
- root@ubuntu:~# hostname (root 是账号, ubuntu 是计算机名称)
- ubuntu
- root@ubuntu:~# hostname yaowenpc (修改主机名称, 这只是临时修改, 重启后就还原, 永久修改要修改配置文件)
- root@yaowenpc:/#
DNS: 解析域名, 计算机没配置 dns 地址是没法上网的, DNS 地址都是由供应商提供的, 要手动指定, 中国电信中国联通都会提供自己的 dns 地址, 无论怎么上网走的网络都是电信或者联通的,(流浪 www.baidu.com 需要 dns 才能到百度服务器)
- root@yaowenpc: /etc# vim resolv.conf (查看 dns 配置文件)
- # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
- # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
- nameserver 127.0.1.1/
nameserver 219.141.136.10 : 电信的 dns
nameserver 202.106.0.20 : 联通的 dns
- ~
- root@yaowenpc:/etc# ping www.baidu.com
- PING www.a.shifen.com (163.177.151.110) 56(84) bytes of data.
- 64 bytes from 163.177.151.110: icmp_seq=1 ttl=128 time=13.9 ms
Curl 工具 (http 工具):
- root@yaowenpc:/etc# curl -v -L www.baidu.com
- * Rebuilt URL to: www.baidu.com/
- * Trying 163.177.151.109...
- * Connected to www.baidu.com (163.177.151.109) port 80 (#0)
- > GET / HTTP/1.1
- > Host: www.baidu.com
- > User-Agent: curl/7.47.0
- > Accept: */*
- >
- < HTTP/1.1 200 OK
- < Server: bfe/1.0.8.18
- < Date: Thu, 15 Feb 2018 07:08:53 GMT
- < Content-Type: text/html
- < Content-Length: 2381
- < Last-Modified: Mon, 23 Jan 2017 13:27:57 GMT
- < Connection: Keep-Alive
- < ETag: "588604dd-94d"
- < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
- < Pragma: no-cache
- < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
- < Accept-Ranges: bytes
- <
- <!DOCTYPE html>
- <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/CSS href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title > 百度一下, 你就知道 </title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hi
- # curl http://www.baidu.com >> /yw/baidu.html
网络测试和测试工具:
排查网络信息: QQ 无法登陆了, 邮箱不能使用了, 网页打不开了
如果自己电脑打不开一个网站, 比如: 被强了, 南北互联 (南方使用的是联通, 北方使用的电信, 导致间断性不能访问)
Ping 是发送数据包到对方主机,
Ping 网关 (网关是一台能够上网的服务器, 通过网关才能够上网), 如果有数据包返回, 表示电脑和网关是互通的, 说明局域网是互通的
有没有配置 dns 地址, 计算机要上网, 需要域名解析, cat /etc/resolv.conf
root@yaowenpc:/# nslookup (nslookup 验证有没有配置 dns 地址, dns 配置的对不对)
> www.baidu.com (nslookup 是一个工具用来解析域名, 输入 www.baidu.com 域名)
Server: 127.0.1.1 (server 127.0.1.1 是主 dns 服务器去解析, 有没有 www.baidu.com 这个域名, 有的话就解析出来, 没有就去别的 dns 服务器上查找)
- Address: 127.0.1.1#53 (Address: 127.0.1.1#53, 其他 dns 服务器从 1 到 53 上面去查找)
- Non-authoritative answer:
- www.baidu.com canonical name = www.a.shifen.com.
(百度的服务器的另 2 个名字和 ip 地址)
- Name: www.a.shifen.com
- Address: 163.177.151.109
- Name: www.a.shifen.com
- Address: 163.177.151.110
- root@yaowenpc:/# nslookup www.baidu.com
- Server: 127.0.1.1
- Address: 127.0.1.1#53
- Non-authoritative answer:
- www.baidu.com canonical name = www.a.shifen.com.
- Name: www.a.shifen.com
- Address: 163.177.151.110
- Name: www.a.shifen.com
- Address: 163.177.151.109
要能够上网: 必须有一个 ip 地址可以跟网关通信, 要有域名解析功能 dns, cat /etc/resolv.conf
Traceroute 是跟踪路由, 访问百度需要经过多少个设备
- root@yaowenpc:/# traceroute www.baidu.com
- traceroute to www.baidu.com (163.177.151.110), 30 hops max, 60 byte packets
- 1 192.168.115.2 (192.168.115.2) 0.140 ms 0.056 ms 0.090 ms
- 2 * * *
- 3 * * *
- 4 * * *
- 5 * * *
- 6 * * *
- root@yaowenpc:/# netstat -r
- Kernel IP routing table
- Destination Gateway Genmask Flags MSS Window irtt Iface
- default 192.168.115.2 0.0.0.0 UG 0 0 0 ens33
- link-local * 255.255.0.0 U 0 0 0 ens33
- 172.17.0.0 * 255.255.0.0 U 0 0 0 docker0
- 192.168.115.0 * 255.255.255.0 U 0 0 0 ens33
来源: http://www.bubuko.com/infodetail-2499060.html