Linux不能上网ping:unknown host,这也太难受了吧!该解决了!

1.先检查linux网卡设置情况
ifconfig

[root@zmhtxdy ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:87:B1:3A
inet addr:10.0.0.11 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe87:b13a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17196 errors:0 dropped:0 overruns:0 frame:0
TX packets:6662 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:22491070 (21.4 MiB) TX bytes:495009 (483.4 KiB)
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:65536 Metric:1
RX packets:179 errors:0 dropped:0 overruns:0 frame:0
TX packets:179 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13076 (12.7 KiB) TX bytes:13076 (12.7 KiB)

可在/etc/sysconfig/network-scripts中编辑ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=e035398d-81ef-41fa-b1d4-942673091a26
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.0.11
PREFIX=24
GATEWAY=10.0.0.2
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
NAME=eth0
HWADDR=00:0C:29:87:B1:3A
LAST_CONNECT=1589358976
NETMASK=255.255.255.0

2.设置网关的网卡,注意添加GATEWAY,与vment8的网关一样即可
进入 /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=zmhtxdy
GATEWAY=10.0.0.2

3.设置服务器的DNS,编辑/etc/resolv.conf

Generated by NetworkManager

nameserver 114.114.114.114
nameserver 10.0.0.2

No nameservers found; try putting DNS servers into your

ifcfg files in /etc/sysconfig/network-scripts like so:

DNS1=114.114.114.114

DNS2=10.0.0.2

DOMAIN=lab.foo.com bar.foo.com

5.重启网络服务,service network restart

6.ping www.baidu.com 即可

你可能感兴趣的:(笔记)