2019-05-26
网络配置
临时ip地址:
dhclient eth0 ---自动获取IP地址
ifconfig eth0 192.168.1.11/24 --指定ip地址并指定掩码
route add default gw 129.168.1.1 --指定网关(为了能和其他网段通信)
netstalt -nr --查看是否生效
route add -net 172.16.0.0/24 gw 192.168.1.100 eth0--添加网段
route -n--查看路由表
vi /etc/resolv.conf (依次写入:nameserver 8.8.8.8 ) --配置DNS服务器地址(编辑配置文件方式)
echo nameserver 192.168.1.1 --配置DNS服务器地址(命令方式)
固定ip地址:
编辑网卡配置文件
vi /etc/network/interfaces --配置文件位置
参数:
auto eth0 ---本机网卡
iface eth0 inet static --设置为静态ip(自动为iface eth0 inet dhcp)
address 192.168.20.1 --固定ip地址
netmask 255.255.255.0 --子网掩码
network 192.168.20.0 --网络地址-(非必填项)
broadcast 192.168.20.255 --广播地址(非必填项)
gateway 192.168.20.2 --网关
dns-nameserver 192.168.1.1 192.168.1.2 --dns服务器配置
up route add -net 172.16.5.0/24 gw 192.168.10.100 eth1 --网卡启动时配置配置网络路由(非必填项)
down route del -net 172.24.0.0/24 --关机时删掉配置(非必填项)