2017年4月

虽然搞了这么久服务器,但都是IDC装好了交过来给ssh,自己再接手.网络方面最多是追加ip.
还没有自己装过系统. 最近想改改工作方式,开发测试环境用虚拟机linux,虚拟机通过vsftp / ssh 登录.
测试ip就是虚拟机ip.
这网络设置方面可折腾得我.也是第一次用 VMware ,以前用的是 vbox6那个.
搞好了,记录下.

电脑上的操作

禁用 VMware Network Adapter VMnet1

配置 VMware Network Adapter VMnet8的 ip是 192.168.137.1 255.255.255.0

配置电脑的网络连接共享给这个 VMnet8.

虚拟机上设置网络连接方式 = 自定义 VMnet8[NAT 模式]

配置 linux ip

DEVICE=eth0
TYPE=Ethernet
#UUID=50e75b7b-f4d3-436e-b392-69995645fb09
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.137.2
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
HWADDR=00:0C:29:97:B5:1B


[root@hq network-scripts]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Error: Connection activation failed: Device not managed by NetworkManager or 

unavailable
                                                           [FAILED]
[root@hq network-scripts]# chkconfig NetworkManager off
[root@hq network-scripts]# service NetworkManager stop
Stopping NetworkManager daemon:                            [  OK  ]
[root@hq network-scripts]# service network restart
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Determining if ip address 192.168.137.2 is already in use for device eth0...
 
#关于
#Bringing up interface eth0:  Error: Connection activation failed: Device not managed by NetworkManager or unavailable以及配置总是不生效原因在Centos6.0以上才会出现这个原因;服务器上安装了图形的,客户在图形界面上配置了ip;
而我习惯在字符界面配置ip ; 而 NetworkManager 和Network两个服务都要管理网卡,这两者之间起了冲突


[root@hq network-scripts]# ping 192.168.137.1
PING 192.168.137.1 (192.168.137.1) 56(84) bytes of data.
From 192.168.137.2 icmp_seq=1 Destination Host Unreachable



[root@hq network-scripts]# ping 192.168.1.1
connect: Network is unreachable

105.jpg
图105 发现,电脑已经能ping通虚拟机的网关和虚拟机 ,但虚拟机ping不出来

尝试关闭ipsec ,无果.

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

图106 配置防火墙后,电脑的ssh能登录虚拟机,虚拟机还是ping不出.似乎没有网关路由一样.

重新设置网关一次,重启网卡,能ping能电脑和路由器了.出能直接ping通外网ip

不能直接ping通域名

图107

确认的网卡配置为

DEVICE=eth0
TYPE=Ethernet
#UUID=50e75b7b-f4d3-436e-b392-69995645fb09
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.137.2
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
HWADDR=00:0C:29:97:B5:1B

======================
vim /etc/resolv.conf
添加dns 
nameserver 223.5.5.5
nameserver 8.8.4.4

图108直接ping域名成功

疑问:

感觉网卡配置第一次和修改那次一样的,等第二次实践再试了.