22.06.23.04(网络IP地址配置)
- 1.4 网络配置
- ifconfig eth0 192.168.1.111/24 # 24位掩码 ,配置临时IP地址
- route add default gw 192.168.1.1 # 配置默认路由
- echo nameserver 8.8.8.8 > /etc/resolv.conf # 配置DNS 服务器
- 注意: 在安装完操作系统时,而直接配置临时IP地址,可能会报错
- 报错过程:
- 可以正常配置临时 IP地址,但是在配置网关时则提示 “SIOCADDRT:网络不可达”
- 原因:
- 是因为 网卡配置文件中 缺少了 auto eth0 和 iface eth0 inet dhcp 这两项
- 解决方法:
- vim /etc/network/interfaces # 修改网卡配置文件,在末行中添加
- 如下两项:
- auto eth0
- iface eth0 inet dhcp
- root@piloteer101:~# /etc/init.d/networking restart # 重启网络服务
- 重新配置:
- root@piloteer101:~# ifconfig eth0 192.168.1.111/24 # 配置临时IP地址
- root@piloteer101:~# route add default gw 192.168.1.1 # 配置默认路由
- root@piloteer101:~# echo nameserver 8.8.8.8 > /etc/resolv.conf # 配置DNS服务器
- 注意: 如果重启网络服务后再配置仍然出现同样的报错,则需要重启系统
- root@piloteer101:~# reboot
- 重启完成后,再重新配置即可。