Centos_DHCP+NAT.sh

#!/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值