网上大多数关于固定ip还能上网的教程都是关于VMware虚拟机的,还有很多方案要么只能固定ip无法ping通外网,要么能上网,虚拟机或电脑一重启ip就变了,结合网上各种方法总结出了一套即能固定ip又能上网的办法。
解决思路,两张网卡,一张负责连接外网,一张负责ssh连接




子网掩码就是:255.255.255.0
ip地址需要和虚拟机中ssh连接的那块网卡设置同一网段,即前三段一致即可
192.168.137.xxx
这里的ip地址最后以为最好就设置为1

给虚拟机添加一块新网卡

选择刚才创建的那张网卡
虚拟机内设置新网卡的配置
将原配置复制一份
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1
编辑第一块网卡(负责连接外网的)
vi /etc/sysconfig/network-scripts/ifcfg-eth0

编辑第二块网卡(负责ssh连接的)
vi /etc/sysconfig/network-scripts/ifcfg-eth1

且需要把UUID给删除了
service network restart
重启网卡