Answers to: iptables firewall problem openvpn bridgedhttp://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged<p>Hi, i think i got some probs with my iptables firewall, my setup is i got a pc (debian installed) with 2 ethernetcard, eth0 connected to my lan(192.168.1.0/24) eth1 for internet connection (ppp0) I have an openvpn server on that pc in bridged mode, the vpn clients can connect but can't ping the server or any other pc on my lan and the server or my lan pcs can't ping the clients. The bridge is setup correctly and the setup of the openvpn server looks right and the clients got an ip from my lan and a route to it so routing looks fine, problem must be the iptables firewall. The requierements for the firewall are : my Lan can do anything except receiving or posting windows shares, netbios etc over the internet or vpn the vpn clients can do anything except receiving or posting windows shares, netbios etc over the vpn and they can not access the internet over the vpn.</p> <p>Please if someone could have a look at my script?</p> <p>Heres the interesting part of my firewall script: <code></p> <h3>The iptables command. Shorter and sure</h3> <p>ipt="/sbin/iptables"</p> <h3>The network interface</h3> <p>ifLan=eth0 ifWan=ppp0 ifVpnB=br0 ifVpn=tap+</p> <p>VPN_PORT=1195</p> <h3>FIREWALL STOP</h3> <p>...</p> <h3>FIREWALL START/RELOAD/RESTART</h3> <p>echo "Building firewall..."</p> <h3>Modules</h3> <p>modprobe ip_tables modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ipt_MASQUERADE modprobe ipt_state modprobe ipt_LOG modprobe iptable_nat modprobe iptable_filter</p> <h3>Flush current rules.</h3> <p>$ipt -F INPUT $ipt -F OUTPUT $ipt -F FORWARD $ipt -t nat -F PREROUTING $ipt -t nat -F POSTROUTING $ipt -t nat -F OUTPUT $ipt -F $ipt -X</p> <h3>Set default policies</h3> <p>$ipt --policy INPUT DROP $ipt --policy OUTPUT ACCEPT $ipt --policy FORWARD DROP $ipt -t nat --policy PREROUTING ACCEPT $ipt -t nat --policy POSTROUTING ACCEPT</p> <h3>SYN flood protection</h3> <p>echo "1" > /proc/sys/net/ipv4/tcp_syncookies</p> <h3>Forwarding</h3> <p>echo "1" > /proc/sys/net/ipv4/ip_forward</p> <h3>LOOPBACK</h3> <p>echo "Setting LOOPBACK rules" $ipt -A INPUT -i lo -j ACCEPT</p> <p>$ipt -A OUTPUT -o lo -j ACCEPT</p> <h3>WAN</h3> <p>echo "Setting WAN rules" $ipt -A INPUT -i $ifWan -p udp --dport $VPN_PORT -m state --state NEW -j ACCEPT $ipt -A INPUT -p tcp --dport 137:139 -i $ifWan -j DROP $ipt -A INPUT -p udp --dport 137:139 -i $ifWan -j DROP $ipt -A INPUT -p tcp --dport 445 -i $ifWan -j DROP $ipt -A INPUT -p udp --dport 445 -i $ifWan -j DROP $ipt -A INPUT -i $ifWan -m state --state ESTABLISHED,RELATED -j ACCEPT</p> <p>$ipt -A OUTPUT -p tcp --dport 137:139 -o $ifWan -j DROP $ipt -A OUTPUT -p udp --dport 137:139 -o $ifWan -j DROP $ipt -A OUTPUT -p tcp --dport 445 -o $ifWan -j DROP $ipt -A OUTPUT -p udp --dport 445 -o $ifWan -j DROP $ipt -A OUTPUT -o $ifWan -j ACCEPT</p> <p>$ipt -A FORWARD -p tcp --dport 137:139 -o $ifWan -j DROP $ipt -A FORWARD -p udp --dport 137:139 -o $ifWan -j DROP $ipt -A FORWARD -p tcp --dport 445 -o $ifWan -j DROP $ipt -A FORWARD -p udp --dport 445 -o $ifWan -j DROP</p> <p>$ipt -A FORWARD -i $ifWan -o $ifLan -m state --state ESTABLISHED,RELATED -j ACCEPT $ipt -A FORWARD -i $ifWan -o $ifVpnB -m state --state ESTABLISHED,RELATED -j ACCEPT $ipt -A FORWARD -i $ifWan -o $ifVpn -m state --state ESTABLISHED,RELATED -j ACCEPT</p> <h3>VPN</h3> <p>echo "Setting VPN rules" $ipt -A INPUT -i $ifVpn -m state --state ESTABLISHED,RELATED -j ACCEPT</p> <p>$ipt -A OUTPUT -o $ifVpn -j ACCEPT</p> <p>$ipt -A FORWARD -i $ifVpn -o $ifLan -j ACCEPT $ipt -A FORWARD -i $ifVpn -o $ifWan -j ACCEPT $ipt -A FORWARD -i $ifVpn -o $ifVpnB -j ACCEPT</p> <h3>BRIDGE</h3> <p>echo "Setting BRIDGE rules" $ipt -A INPUT -i $ifVpnB -j ACCEPT </p> <p>$ipt -A OUTPUT -o $ifVpnB -j ACCEPT </p> <p>$ipt -A FORWARD -i $ifVpnB -o $ifWan -j ACCEPT $ipt -A FORWARD -i $ifVpnB -o $ifLan -j ACCEPT $ipt -A FORWARD -i $ifVpnB -o $ifVpn -j ACCEPT</p> <h3>LAN</h3> <p>echo "Setting LAN rules" $ipt -A INPUT -i $ifLan -j ACCEPT </p> <p>$ipt -A OUTPUT -o $ifLan -j ACCEPT</p> <p>$ipt -A FORWARD -i $ifLan -o $ifWan -j ACCEPT $ipt -A FORWARD -i $ifLan -o $ifVpnB -j ACCEPT $ipt -A FORWARD -i $ifLan -o $ifVpn -j ACCEPT</p> <h3>Portforwarding</h3> <p>...</p> <h3>Masquerading</h3> <p>$ipt -t nat -A POSTROUTING -j MASQUERADE echo "Done!" </code></p> <p>thx Grobi</p>enTue, 03 Aug 2010 11:24:20 -0400Answer by Lozmanhttp://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1172<p>Firstly, why are you using Bridged mode if you are blocking NetBIOS communication between clients and network? This is the main reason to use bridged mode in my opinion. If you don't need to access Windows shares over the VPN then I would suggest routed mode which will simplify the configuration.</p> <p>Having said that, far be it from me to tell you what to do so, have you checked that the network interface adaptor used as part of your bridged interface has sucessfully enabled promiscuous mode? This is a requirement for bridged networking, and a common reason why traffic is not passed from the LAN to the VPN clients.</p> <p>Regards, Lozman.</p>LozmanTue, 03 Aug 2010 11:24:20 -0400http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1172Answer by Grobi 1http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1024<p>something worked out now, the vpn clients can ping each other and the server but no pc on my lan, the server and the pcs on my lan CAN NOT ping the vpn clients. i changed the firewall a litle : </p> <h1>The iptables command. Shorter and sure.</h1> <p>ipt="/sbin/iptables"</p> <h1>The network interface.</h1> <p>ifWan=ppp0 ifVpnB=br0 ifVpn=tap+</p> <p>VPN_PORT=1195</p> <h1>FIREWALL STOP</h1> <p>... </p> <h1>FIREWALL START/RELOAD/RESTART</h1> <p>echo "Building firewall..."</p> <h1>Modules</h1> <p>modprobe ip_tables modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ipt_MASQUERADE modprobe ipt_state modprobe ipt_LOG modprobe iptable_nat modprobe iptable_filter</p> <h1>Flush current rules.</h1> <p>$ipt -F INPUT $ipt -F OUTPUT $ipt -F FORWARD $ipt -t nat -F PREROUTING $ipt -t nat -F POSTROUTING $ipt -t nat -F OUTPUT $ipt -F $ipt -X</p> <h1>Set default policies</h1> <p>$ipt --policy INPUT DROP $ipt --policy OUTPUT ACCEPT $ipt --policy FORWARD DROP $ipt -t nat --policy PREROUTING ACCEPT $ipt -t nat --policy POSTROUTING ACCEPT</p> <h1>SYN flood protection</h1> <p>echo "1" > /proc/sys/net/ipv4/tcp_syncookies</p> <h1>Forwarding</h1> <p>echo "1" > /proc/sys/net/ipv4/ip_forward</p> <h1>LOOPBACK</h1> <p>echo "Setting LOOPBACK rules" $ipt -A INPUT -i lo -j ACCEPT</p> <p>$ipt -A OUTPUT -o lo -j ACCEPT</p> <h1>WAN</h1> <p>echo "Setting WAN rules" $ipt -A INPUT -i $ifWan -p udp --dport $VPN_PORT -m state --state NEW -j ACCEPT $ipt -A INPUT -p tcp --dport 137:139 -i $ifWan -j DROP $ipt -A INPUT -p udp --dport 137:139 -i $ifWan -j DROP $ipt -A INPUT -p tcp --dport 445 -i $ifWan -j DROP $ipt -A INPUT -p udp --dport 445 -i $ifWan -j DROP $ipt -A INPUT -i $ifWan -j ACCEPT</p> <p>$ipt -A OUTPUT -p tcp --dport 137:139 -o $ifWan -j DROP $ipt -A OUTPUT -p udp --dport 137:139 -o $ifWan -j DROP $ipt -A OUTPUT -p tcp --dport 445 -o $ifWan -j DROP $ipt -A OUTPUT -p udp --dport 445 -o $ifWan -j DROP $ipt -A OUTPUT -o $ifWan -j ACCEPT</p> <p>$ipt -A FORWARD -p tcp --dport 137:139 -o $ifWan -j DROP $ipt -A FORWARD -p udp --dport 137:139 -o $ifWan -j DROP $ipt -A FORWARD -p tcp --dport 445 -o $ifWan -j DROP $ipt -A FORWARD -p udp --dport 445 -o $ifWan -j DROP</p> <p>$ipt -A FORWARD -i $ifWan -o $ifVpnB -j ACCEPT $ipt -A FORWARD -i $ifWan -o $ifVpn -j ACCEPT</p> <h1>VPN</h1> <p>echo "Setting VPN rules" $ipt -A INPUT -i $ifVpn -j ACCEPT</p> <p>$ipt -A OUTPUT -o $ifVpn -j ACCEPT</p> <p>$ipt -A FORWARD -i $ifVpn -o $ifWan -j ACCEPT $ipt -A FORWARD -i $ifVpn -o $ifVpnB -j ACCEPT</p> <h1>BRIDGE</h1> <p>echo "Setting BRIDGE rules" $ipt -A INPUT -i $ifVpnB -j ACCEPT </p> <p>$ipt -A OUTPUT -o $ifVpnB -j ACCEPT </p> <p>$ipt -A FORWARD -i $ifVpnB -o $ifWan -j ACCEPT $ipt -A FORWARD -i $ifVpnB -o $ifVpn -j ACCEPT</p> <h1>Portforwarding</h1> <p>...</p> <h1>Masquerading</h1> <p>$ipt -t nat -A POSTROUTING -j MASQUERADE echo "Done!"</p>Grobi 1Sat, 10 Jul 2010 19:01:31 -0400http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1024Answer by Grobi 1http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1021<p>the vpn clients connect from wan side, my dhcp server is configured to provide 192.168.1.2 - 192.168.1.127 to the pcs on my lan and the openvpn internal dhcp gives the clients an ip from 192.168.1.129 - 192.168.1.254, so no collision of those dhcp servers. The only static ip i have is 192.168.1.1 (the server/router/gateway). There is no DMZ, managed routers or switches or what so ever. The vpn session is fully established says the clients log. As you can see in the firewall script i am blocking ports 137-139, 445 (windows shares/netbios stuff) on nearly every interface and opening port 1195 for vpn on ppp0 so that the vpn clients could connect over the internet.</p>Grobi 1Sat, 10 Jul 2010 10:56:24 -0400http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1021Answer by Ronhttp://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1018<p>I can honestly see your issue being anywhere in layers 2-7 of the OSI model. Layer 1 seems fine. I think before you can assume that it's iptables that is the cause of the issue, you need to take it step by step through each layer.</p> <p>Layer 1 - Physical, you have ruled out because of what you've said.</p> <p>Layer 2 - Data Link Layer (which has 2 sub-layers, Logical Link Control and MAC) <em>could</em> be the issue, but I doubt it in this case, unless you are using MAC filtering or something of that nature. Bridges do work at this layer though, as do layer 2 switches.</p> <p>Layer 3 - Network - lots to chew on here. Switches and routers operate here. Do you have a managed switch involved?</p> <p>Layer 4 - Transport - maybe. It could be a protocol issue, but you need to work through the lower layers first.</p> <p>Layer 5 - Session - since you are using VPN, that creates a session (just like applications create sessions too. Could it be something like the session isn't being fully established? Again.. more information is needed.)</p> <p>Layer 6 - Presentation.</p> <p>Layer 7 - Application.</p> <p>As for what you wrote....</p> <p>So eth0 is LAN-side and ppp0 is WAN side, but the vpn clients can connect but can't ping the server or any other pc on my lan and the server or my lan pcs can't ping the clients."</p> <p>Are you connecting your VPN clients from outside your LAN or testing this from within it? Is the server in a DMZ? Is the server in a DMZ that is completely isolated from the LAN or not? Did you subnet something somewhere?</p> <p>Again... more information is needed. We need to rule some things out, gather more data to properly assess the situation.</p> <p>"The bridge is setup correctly and the setup of the openvpn server looks right and the clients got an ip from my lan and a route to it so routing looks fine"</p> <p>These are assumptions. From what you've described thus far, I doubt that things are setup correctly in these areas or on this network or it would all work. Do not rule anything out based on assumptions. When you said the client PCs on the LAN get an IP, I am reading that as you are using DHCP vs. static IPs on your LAN, correct?</p> <p>"problem must be the iptables firewall."</p> <p>Do not assume that. Work through the OSI layers first and be methodical, not jumping around from here to there guessing what it may or may not be. Rule things out after researching and testing first. then move onto the next layer.</p> <p>"The requirements for the firewall are : my Lan can do anything except receiving or posting windows shares, netbios etc over the internet or vpn the vpn clients can do anything except receiving or posting windows shares, netbios etc over the vpn and they can not access the internet over the vpn."</p> <p>So you have blocked port 445 and opened port 1723, correct? How are you enforcing these rules of what people can and cannot do? Solely via iptables or do you have other methods of control involved? Other permissions set elsewhere may be part of, or the cause of your issue.</p> <p>More information is required.</p> <p>Starting at Layer 2, please research, test, confirm that it's working and then post your results here.</p>RonFri, 09 Jul 2010 20:28:50 -0400http://linuxexchange.org/questions/1017/iptables-firewall-problem-openvpn-bridged/1018