#!/bin/bash
#Center_DHCP+NAT.sh
#root@Center:~#vi /etc/sysconfig/network-scripts/ifcfg-eth0
#DEVICE="eth0"
#BOOTPROTO="static"
#HWADDR="00:0c:29:c5:fb:40"
#NM_CONTROLLED="no"
#ONBOOT="yes"
#IPADDR=192.168.94.130
#NETMASK=255.255.255.0
#GATEWAY=192.168.94.2
#
#root@Center:~#vi /etc/sysconfig/network-scripts/ifcfg-eth1
#DEVICE="eth1"
#BOOTPROTO="static"
#HWADDR="00:0c:29:c5:fb:4a"
#NM_CONTROLLED="no"
#ONBOOT="yes"
#IPADDR=192.168.95.2
#NETMASK=255.255.255.0
yum install -y dhcp
echo 'subnet 192.168.95.0 netmask 255.255.255.0 {
range 192.168.95.50 192.168.95.100;
ddns-update-style none;
ignore client-updates;
default-lease-time 259200;
max-lease-time 518400;
option routers 192.168.95.2;
option domain-name "Center";
option domain-name-servers 192.168.95.2;
}' >/etc/dhcp/dhcpd.conf
echo '#!/bin/bash
echo "1" >/proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -i eth1 -j ACCEPT
inetip=$(ifconfig eth0|grep "inet addr:"|cut -d: -f2|awk -F" " '\'{print \$1}\'')
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source $inetip
#iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 192.168.94.130
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "1">/proc/sys/net/ipv4/ip_forward
#vi /etc/sysctl.conf
#net.ipv4.ip_forward = 1
#sysctl -p /etc/sysctl.conf' >/root/iptables.rules
chkconfig dhcpd on
service dchpd restart
echo 'sh /root/iptables.rules' >>/etc/rc.local
Centos_DHCP+NAT.sh
最新推荐文章于 2018-08-09 13:35:46 发布