1

I own a VPS (CentOS 6.5). I have installed OpenVPN on this server. Everything works fine, I can connect and surf, etc. Let's say my IP of the server is: 1.2.3.4. When I connect to my VPS my IP is 1.2.3.4.

I have also installed OpenERP (on the same VPS) which is running on port 8069.

What I am trying to achieve is to block all traffic on port 8069 except the VPN traffic. So, I have to connect to my VPS with OpenVPN to access http://1.2.3.4:8069.

I tried several iptables tutorials on the net, but none of them are working.

For example:

iptables -A INPUT -p tcp -s 1.2.3.4 --dport 8069 -j ACCEPT 
or 
iptables -A INPUT -p tcp -s  10.8.0.0/24 --dport 8069 -j ACCEPT
or
iptables -I INPUT \! --src 10.8.0.0/24 -m tcp -p tcp --dport 8069 -j DROP
or
iptables -I INPUT \! --src 1.2.3.4 -m tcp -p tcp --dport 8069 -j DROP

These are examples. I have tried even more rules. All tutorials I followed block all traffic on port 8069, even if I connect to my VPS with OpenVPN I can't access http://1.2.3.4:8069.

Does anyone have an idea how to block all traffic on port 8069 except my VPN connection? How do I achieve this?

My server.conf is:

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1"
push "dhcp-option DNS 10.8.0.1"
user nobody
group nobody
keepalive 5 30
cipher AES-256-CBC   
comp-lzo
persist-key
persist-tun
verb 5

My client conf is:

dev tun
client
proto udp
remote 1.2.3.4
port 1194
resolv-retry infinite
nobind
redirect-gateway def1
persist-key
persist-tun
ca ca.crt
cert nika-pc.crt
key nika-pc.key
cipher AES-256-CBC   
comp-lzo
ns-cert-type server
verb 5

Thanks in advance.

Edit:

Output: iptables -L -n -v

http://pastebin.com/RhzFBG8R

Output: iptables -L -n -v | head

http://pastebin.com/n6gLe68s

Nika452
  • 11
  • 4

2 Answers2

1

My word, that's a complex firewall setup (although an awful lot of the rules have zero packet counts, which makes me think there's a lot of historical cruft in there). Rather than poring through, trying to work out which existing rule is catching this traffic in error, I suggest we cut through and just put the relevant rules at the top:

iptables -I INPUT 1 -p tcp -i tun+ --dport 8069 -j ACCEPT
iptables -I INPUT 2 -p tcp --dport 8069 -j REJECT

Edit: I really do encourage you to edit the updates into your question, instead of leaving an endless series of pastebin links, which may or may not stay put over time. In any case, thanks for the new output. As you can see, the packet counts on the first rule are zero, which those on the second (blanket refusal) rule are most definitely not. The only conclusion left is that you are mistaken about this traffic using the OpenVPN connection; it's pretty clearly coming over the plaintext internet. If you want to be completely sure, add a third rule in between the two above, with

iptables -I INPUT 2 -p tcp --dport 8069 -j LOG --log-prefix "CARROT: "

Unless the word CARROT turns up in your logfiles a lot, it should be easy to find the output from those matches in your system logs (/var/log/messages, or as syslog/your distro deems appropriate), and they should confirm which interface the packets being refused are coming in on. I don't expect it to be tun0.

MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Not working :( rejecting all traffic, even tun+. – Nika452 Dec 29 '13 at 20:20
  • And what are the packet counts on those new rules after you do that? (Try `iptables -L -n -v | head`, and *editing the output into your question*.) – MadHatter Dec 30 '13 at 06:23
  • Thanks for the reply MadHatter. This is the output: http://pastebin.com/n6gLe68s – Nika452 Dec 30 '13 at 15:41
  • I have checked the messages file. Here's an example: [link]Dec 30 17:20:15 thor kernel: CARROT: IN=eth0 OUT= MAC=00:16:3e:34:48:2b:00:04:80:df:6b:00:08:00 SRC=77.173.xxx.xx (home ip) DST=159.253.x.xxx (server ip) LEN=48 TOS=0x00 PREC=0x00 TTL=120 ID=26068 DF PROTO=TCP SPT=64211 DPT=8069 WINDOW=8192 RES=0x00 SYN URGP=0 [/link] So it reads my source IP and that's the reason why I'm blocked? PS: I'll update everything in my Q. – Nika452 Dec 30 '13 at 16:36
0

I add a answer because I can't add a comment. I think that the protocol used is udp and not tcp so

iptables -I INPUT 1 -p udp -i tun+ --dport 8069 -j ACCEPT
iptables -I INPUT 2 -p udp --dport 8069 -j REJECT
dwarf
  • 21
  • 3