网络配置
12.15'23
查看 ip 地址
私有地址
hostname -I
ifconfig
ip addr show
ip a
Mac
For wireless: Use
ipconfig getifaddr en1
For ethernet, the Wi-Fi network adapter: Use
ipconfig getifaddr en0.
公开地址
使用 curl 或 wget 向外网发请求,如 http://ident.me
,http://ipecho.net/plain
,会返回公开 ip。
curl ident.me
查看监听端口和对应的服务
Linux
netstat -tulnp
-
t: TCP 协议
-
u: UDP 协议
-
l: 正在监听的服务
-
n: 数字表示端口,不解析名字
-
p: 显示连接的进程号、名字
-
a: 所有连接协议(默认:已连接的)
MacOS
lsof -i -P | grep 5000
查看网络硬件和软件
lshw -C network
lsusb
iwconfig
ipconfig
查看路由
# Linujx
route
# MacOS
traceroute 127.0.0.1
# Windows
tracert 127.0.0.1
Browser: whatismyipaddress.com
常用诊断命令
nslookup ubuntu.com
ping 127.0.0.1 -n 30
配置文件
/etc/network/interfaces
/etc/resolv.conf
/etc/wpa_supplicant/wpa_supplicant.conf
重载无线网卡驱动
sudo rmmod rtl8xxxu && modprobe rtl8xxu
查看驱动消息
dmesg
hosts
HTTP 协议访问某些网站特别慢,可能是域名解析出错了,手动修改
/etc/hosts
USB wifi adapter
aborting-authentication-by-local-choice-reason-3-deauth-leaving-when-trying
# 连接 wifi 网络
sudo nmcli dev wifi connect <MySSID>
# 查看日志
dmesg
# 名字太长导致出错
ln -s /dev/null /etc/systemd/network/99-default.link
dns 解析出错导致无法访问任意网站
测试 dns 服务是否可用
nslookup ubuntu.com
修改 dns 服务器地址(常用 8.8.8.8),等一段时间后生效
CentOS7: /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=8.8.8.8
Ubuntu: /etc/systemd/resolved.conf
DNS=8.8.8.8
vagrant 虚拟机安装 centos7
网络出错
network[3304]: RTNETLINK answers: File exists
解决方案:
可能是由于网卡配置冲突导致的,把/etc/sysconfig/network-scripts/ifcfg-*
配置中 UUID 和 HWADDR 删除
主机无法访问虚拟机 ssh 以外的端口
centos7
默认开启了防火墙,需要使用firewall-cmd
手动开放端口
查看状态
firewall-cmd --list-all
打开端口(80 为例,设置成永久)
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
firewall-cmd --list-all
centos6 以前
使用 iptables
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo service iptables save
📖