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"# 修改網卡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"# 啟用端口轉發(NAT)功能"echo 1 > /proc/sys/net/ipv4/ip_forwardecho"# 修改防火墻設置,將網卡eth1改成trusted區域:"
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 規則:將所有發送到 eth1(192.168.100.100) 的數據包轉發到 eth0(外網網卡)"#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"# 允許端口轉發,執行命令"
iptables -A FORWARD -i eth1 -j ACCEPT