我更新我的问题。
我向堆栈溢出提出同样的问题,但最好在这里问。
在安装了最少的操作系统后,我在配置工作站网络时遇到了麻烦。我编辑vi /etc/sysconfig/network-scripts/ifcfg-em1
为静态。从谷歌搜索中,我一次又一次地重新启动我的网络服务。但仍然无法连接到互联网或 ping(除了ping 127.0.0.1
)。这是我的配置。
[root@workstation ~]# uname -a
Linux workstation.XXXXX 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@workstation ~]# ifconfig
em1 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX
inet addr:aaa.bbb.ccc.xxx Bcast:aaa.bbb.211.255 Mask:255.255.252.0
inet6 addr: XXXX::XXXX:XXX:XXXX:XXXX/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12465754 errors:0 dropped:0 overruns:0 frame:0
TX packets:238 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1507354446 (1.4 GiB) TX bytes:35268 (34.4 KiB)
Interrupt:16
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:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1316 (1.2 KiB) TX bytes:1316 (1.2 KiB)
[root@workstation ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
inet aaa.bbb.ccc.xxx/22 brd aaa.bbb.211.255 scope global em1
inet6 XXXX::XXXX:XXXX:XXXX:XXXX/64 scope link
valid_lft forever preferred_lft forever
3: em2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
[root@workstation ~]# vi /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
HWADDR=54:9F:35:1F:58:D0
TYPE=Ethernet
UUID=7337edf4-f9f0-4dab-9d3d-6f031e7180cc
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=aaa.bbb.ccc.132
NETMASK=255.255.252.0
NAME="System em1"
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
PREFIX=22
GATEWAY=aaa.bbb.156.5
DNS1=aaa.bbb.10.2
DOMAIN=168.126.63.1
[root@workstation ~]# service network restart
Shutting down interface em1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface em1: Determining if ip address aaa.bbb.208.132 is already in use for device em1...
[ OK ]
[root@workstation ~]# yum list
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base
[root@workstation ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=workstation.XXXXX
GATEWAY=aaa.bbb.156.5
谢谢您的回答,是的,@larsks em1 是静态 IP,而不是 DHCP。这是ip路由
[root@workstation ~]# ip route
aaa.bbb.ccc.0/22 dev em1 proto kernel scope link src aaa.bbb.ccc.xxx
169.254.0.0/16 dev em1 scope link metric 1002
这是vi /etc/resolv.conf
[root@workstation ~]# vi /etc/resolv.conf
nameserver aaa.bbb.10.2
search 168.126.63.1
我改成NETWORK
,GATEWAY
但还是无法连接互联网。
另外,非常感谢您对我的帮助。我认为,我们已经接近解决方案了。
答案1
最后我解决了问题。
[root@workstation network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
aaa.bbb.ccc.0 0.0.0.0 255.255.252.0 U 0 0 0 em1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1
不存在“默认网关”,
[root@workstation network-scripts]# ip route add 155.230.156.5 dev em1
[root@workstation network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
aaa.bbb.156.5 0.0.0.0 255.255.255.255 UH 0 0 0 em1
aaa.bbb.ccc.0 0.0.0.0 255.255.252.0 U 0 0 0 em1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1
接下来,
[root@workstation network-scripts]# route add default gw 155.230.156.5 dev em1
[root@workstation network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
aaa.bbb.156.5 0.0.0.0 255.255.255.255 UH 0 0 0 em1
aaa.bbb.ccc.0 0.0.0.0 255.255.252.0 U 0 0 0 em1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1
0.0.0.0 aaa.bbb.156.5 0.0.0.0 UG 0 0 0 em1 ← "default GATEWAY"
确认连接,
[root@workstation network-scripts]# ping www.google.co.kr
PING www.google.co.kr (216.58.199.99) 56(84) bytes of data.
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=1 ttl=50 time=82.8 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=2 ttl=50 time=47.2 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=3 ttl=50 time=46.9 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=4 ttl=50 time=47.0 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=5 ttl=50 time=57.3 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=6 ttl=50 time=47.0 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=7 ttl=50 time=47.6 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=8 ttl=50 time=47.6 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=9 ttl=50 time=46.9 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=10 ttl=50 time=47.0 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=11 ttl=50 time=47.5 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=12 ttl=50 time=47.0 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=13 ttl=50 time=47.5 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=14 ttl=50 time=57.8 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=15 ttl=50 time=47.5 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=16 ttl=50 time=47.4 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=17 ttl=50 time=53.0 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=18 ttl=50 time=47.6 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=19 ttl=50 time=47.5 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=20 ttl=50 time=47.5 ms
64 bytes from hkg07s22-in-f3.1e100.net (216.58.199.99): icmp_seq=21 ttl=50 time=47.0 ms
^C
--- www.google.co.kr ping statistics ---
21 packets transmitted, 21 received, 0% packet loss, time 20694ms
rtt min/avg/max/mdev = 46.961/50.269/82.824/7.940 ms
但是,当我reboot
或时service network restart
,它恢复了。现在我想知道如何永久保存它。
我对 Linux 网络有了一些了解。再次感谢您对我的帮助。