rhel 6 虚拟机连接互联网

切换到 /etc/sysconfig/network-scripts/ 知道自己的网卡名称(用ifconfig命令 ) 用vim打开对应的文件

添加如下内容(如果已经有相同的参数存在,则修改)

[root@admin network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:B2:F3:30  #网卡名称
 inet addr:192.168.221.128  Bcast:192.168.221.255  Mask:255.255.255.0
 inet6 addr: fe80::20c:29ff:feb2:f330/64 Scope:Link
 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 RX packets:4845 errors:0 dropped:0 overruns:0 frame:0
 TX packets:2956 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000 
 RX bytes:1757331 (1.6 MiB)  TX bytes:435030 (424.8 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:16436  Metric:1
 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:0 
 RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
[root@admin network-scripts]# cd /etc/sysconfig/network-scripts/ | ls
ifcfg-eth0   ifdown-ippp  ifdown-routes  ifup-bnep  ifup-plip    ifup-sit          network-functions
[root@admin network-scripts]# vim ifcfg-eth0 
DEVICE=eth0
HWADDR=00:0C:29:B2:F3:30
TYPE=Ethernet
UUID=0b622218-431e-4f5d-b828-4f23c5c3fef7
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp          #1 这三点要改
NETMASK=255.255.255.0   #2
DNS=114.114.114.114     #3

需要修改的参数:

BOOTPROTO=dhcp
NETMASK=255.255.255.0
DNS=114.114.114.114

重启服务

service network restart
上一篇:Docker 学习笔记 - 网络的端口映射


下一篇:一次云服务器安装达梦数据库后无法远程访问问题处理