安裝了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沒有配置好,解決方案見44、修改/etc/resolv.conf
增加一行:
nameserver 10.10.1.2
重啓網絡服務,再ping 百度就OK