安装了SUSE 发现ip为自动获取的,欲改为静态地址
1、设置/etc/sysconfig/network/ifcfg-eth0为
BOOTPROTO='static'
STARTMODE='auto'
DEVICE=eth0
BROADCAST=10.10.37.255
IPADDR=10.10.37.114
NETMASK=255.255.255.0
NETWORK=10.10.37.0
GATEWAY=10.10.37.100
TYPE=Ethernet
DNS='10.10.1.2'
2、完成之后使用
service network restart
重启,运行ifconfig查看ip地址:
eth0 Link encap:Ethernet HWaddr 00:0C:29:83:8A:23
inet addr:10.10.37.114 Bcast:10.10.37.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe83:8a23/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2808 errors:0 dropped:0 overruns:0 frame:0
TX packets:1488 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:216495 (211.4 Kb) TX bytes:192077 (187.5 Kb)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:38 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2832 (2.7 Kb) TX bytes:2832 (2.7 Kb)
好像配置好了,但是运行
ping www.baidu.com
得到:
ping: unknown host www.baidu.com
首先看看能不能ping通DNS服务器:
ping 10.10.1.2
得到
connect: Network is unreachable
看来连DNS服务器都ping不通。解决方案见3
3、运行
netstat -r
查看路由信息:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.10.37.0 * 255.255.255.0 U 0 0 0 eth0
loopback * 255.0.0.0 U 0 0 0 lo
link-local * 255.255.0.0 U 0 0 0 eth0
没有网关的表项,说明网关没有配置好。
编辑/etc/sysconfig/network/routes
添加一行:
default 10.10.37.100
重启网络服务
service network restart
再次查看路由信息:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default 10.10.37.100 0.0.0.0 UG 0 0 0 eth0
10.10.37.0 * 255.255.255.0 U 0 0 0 eth0
loopback * 255.0.0.0 U 0 0 0 lo
link-local * 255.255.0.0 U 0 0 0 eth0
有网关了,再次pingDNS服务器:
ping 10.10.1.2
可以ping 通
再次ping baidu:
ping www.baidu.com
得到:
ping: unknown host www.baidu.com
直接ping 百度的ip:
ping 119.75.218.77
可以ping通,说明DNS没有配置好,解决方案见4
4、修改/etc/resolv.conf
增加一行:
nameserver 10.10.1.2
重启网络服务,再ping 百度就OK