share-eth.sh#!/bin/sh# use to share the two network card and make the eth0 linked public network, eth1 linked LAN.# And make the post data of eth1 would be sent to eth0.echo"# 修改網(wǎng)卡eth1"sed -i 's/IPADDR=.*/IPADDR=192.168.100.100/g' /etc/sysconfig/network-scripts/ifcfg-eth1
sed -i 's/ONBOOT=.*/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-eth1
sed -i 's/BOOTPROTO=.*/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth1
service network restartecho"# 啟用端口轉(zhuǎn)發(fā)(NAT)功能"echo 1 > /proc/sys/net/ipv4/ip_forwardecho"# 修改防火墻設(shè)置,將網(wǎng)卡eth1改成trusted區(qū)域:"
systemctl stop NetworkManager
systemctl disable NetworkManager
firewall-cmd --permanent --zone=public --remove-interface=eth1
firewall-cmd --permanent --zone=trusted --add-interface=eth1
firewall-cmd --reload
systemctl restart firewalldecho"# 配置 NAT 規(guī)則:將所有發(fā)送到 eth1(192.168.100.100) 的數(shù)據(jù)包轉(zhuǎn)發(fā)到 eth0(外網(wǎng)網(wǎng)卡)"#ip=$(awk -F "=" '/^IPADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth1)
iptables -t nat -A POSTROUTING -s "192.168.100.100/255.255.255.0" -o eth0 -j MASQUERADEecho"# 允許端口轉(zhuǎn)發(fā),執(zhí)行命令"
iptables -A FORWARD -i eth1 -j ACCEPT