1.查看当前网络设置
- ifconfig
ifconfig eth0; #查看eth0接口网络设置
ifconfig -a #查看所有网络接口的信息
- route 显示路由表
route | grep default 显示主机的默认网关。
- ping -c 4 192.168.1.10 发送指定数量的数据包进行网络连接测试。
- traceroute 192.168.1.10 测试与其他主机的网络连接路径。
- hostname 显示当前主机名称。
- ifdown eth0 && ifup eth0 用来重启eth0网卡
2.修改配置文件进行网络配置
- CentOS网卡eth0的配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0
- Ubuntu网卡eth0的配置文件:/etc/network/interfaces
2.1网络接口配置文件 :
- CentOS设置静态IP 地址内容如下 :
DEVICE=eth0 #设置网络接口名称
ONBOOT=yes #设置网络接口在系统启动时激活。
BOOTPROTO=static #配置为静态地址
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #网络接口的默认网关
DNS1=8.8.8.8
DNS2=4.4.4.4
- CentOS使用DHCP 方式获得网络配置内容:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
- Ubuntu设置静态IP 地址内容如下 :
auto eth0
iface eth0 inet static
address 192.168.1.75
gateway 192.168.1.1
netmask 255.255.255.0
dns-nameservers 8.8.8.8
dns-nameservers 4.4.4.4
- Ubuntu使用DHCP 方式获得网络配置内容 :
auto eth0
iface eth0 inet dhcp
2.2查看生效的DNS(通用)
cat /etc/resolv.conf
3.ubuntu的iptables设置
这篇文章不错:
Linux(Ubuntu) iptables使用小记