1.真机配置:
vi
当连上网后vim /etc/resolv.conf**
~~~~~~~
nameserver 172.20.10.1 #此处的ip为dns解析的ip
~~~~~~~
2.第二步:配置火墙攻略
systemctl start firewalld.service ##打开火墙服务
firewall-cmd –list-all ##查看火墙信息等
firewall-cmd –permanent –add-masquerade ##添加伪装
firewall-cmd –permanent –add-rich-rule=”rule family=”ipv4” source address=192.168.122.1/24 masquerade” **##添加策略 ,使得所有ip都以指定的**address=192.168.12ip出去,注:此处的ip来自virbr0
systemctl restart firewalld.service ##重启火墙服务
firewall-cmd –list-all ##查看火墙信息
第三部:安装dhcp服务(目的:分配ip,自动更新网关)
yum install -y dhcp
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
~~~~~~~
7 option domain-name “zpy.org”; ##指定域名
8 option domain-name-servers 172.20.10.1; ##指定客户主机获得到的dns 这个在真机/etc/resolv.conf 里面查
27 #subnet 10.152.187.0 netmask 255.255.255.0 {
28 #}
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.23 172.25.254.123;
34 option routers 172.25.254.20;}
}
36行后面删掉
systemctl restart dhcpd
客户端(虚拟机)配置:
第一步:从nm-connection-editor加dhcp的ip
第二步:设置网关:
vim /etc/sysconfig/network
~~~~
GATEWAY=真机ip
~~~~
测试:
ping www.baidu.com