|
用VBOX搞一个iptables测试环境,第一台虚拟机guest1设置两个网卡,eth0为NAT eth1 则用一个虚拟网卡和第二台虚拟机 guest2的虚拟网卡创建一个网桥,现在guest1可以上网,也可以连接上guest2(SSH),但是我在guest1上用iptables将 eth1转发到eth0上,但是在guest2 DNS不行(DNS端口己开放)
确认VOBX的网络有问题,每次开机要重启网络才行
我的规则的确有问题,因为只开转发,GETUST2 上WGET网站是没问题的但用下面的规则后就连不上了 请大家请帮看看
#!/bin/sh
iptables -F
iptables -X
iptables -Z
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
# open forward
echo 1 >/proc/sys/net/ipv4/ip_forward
#localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A INPUT -i eth1 -j ACCEPT
#DNS
iptables -A FORWARD -p udp --dport 53 -j ACCEPT
# iptables -A INPUT -p udp --dport 53 -j ACCEPT
# iptables -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp --dport 53 -j ACCEPT
#FTP
# iptables -A POSTROUTING -s 192.168.1.0/24 -p tcp --dport 53 -o eth0 -j MASQUERADE
iptables -A FORWARD -p tcp --dport 21 -j ACCEPT
#SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#PING
iptables -A INPUT -p icmp -j ACCEPT
#E-mail SMTP POP3
iptables -A FORWARD -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp --dport 110 -j ACCEPT
iptables -A FORWARD -p udp --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp --dport 143 -j ACCEPT
iptables -A FORWARD -p udp --dport 143 -j ACCEPT
iptables -A FORWARD -p tcp --dport 993 -j ACCEPT
iptables -A FORWARD -p udp --dport 993 -j ACCEPT
iptables -A FORWARD -p tcp --dport 995 -j ACCEPT
iptables -A FORWARD -p udp --dport 995 -j ACCEPT
#MSN,1863,443, QQ,8000,4000,443
iptables -A FORWARD -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -A FORWARD -p tcp --dport 8000 -j ACCEPT
iptables -A FORWARD -p udp --dport 8000 -j ACCEPT
iptables -A FORWARD -p udp --dport 4000 -j ACCEPT
#SNAT eth1 to eth0 (DHCPip)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# forward 80 to squid 8080
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
#
只开转发WGET是正常的
我只用转发规则在GUEST2上用WGET正常,但DNS 53仍然不通
我要DNS和pacman等都能正常使用,规则应该怎么改?
#!/bin/sh
# open forward
echo 1 >/proc/sys/net/ipv4/ip_forward
#SNAT eth1 to eth0 (DHCPip)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# forward 80 to squid 8080
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 |
|