Linux從入門到放棄 iptables SNAT源地址轉發

公網

[root@7 ~]# iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j SNAT --to-source 192.168.1.1
[root@7 ~]# vim /etc/sysctl.conf

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

net.ipv4.ip_forward = 1	# 添加 (開啓內核轉發)
[root@7 ~]# sysctl -p
net.ipv4.ip_forward = 1

內網

[root@wy ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=no	#修改爲no
[root@wy ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth1
UUID=1aede700-0060-4845-9365-e38da9621f62
DEVICE=eth1
ONBOOT=yes
IPADDR=172.16.1.7
PREFIX=24
GATEWAY=192.168.1.1	# 修改爲有公網的IP地址
DNS1=114.114.114.114	# 添加DNS
IPV6_PRIVACY=no
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章