2

I'm trying to restrict access to a particular port for a particular user on my Debian.

Let's say user's id is 1000 and port I would like to block is 5000.

I tried using iptables with the following command :

iptables -I OUTPUT -o lo -p tcp --dport 5000 --match owner --uid-owner 1000 -j DROP

It works if the user does curl 127.0.0.1:5000 or curl <machine_ip>:5000 but not if the user execute curl localhost:5000.

I don't understand why it's not working. I though localhost was converted to 127.0.0.1. What's the difference ?

In my /etc/hosts file, I have

127.0.0.1   localhost

# The following lines are desirable for IPv6 capable hosts
::1 localhost   ip6-localhost ip6-loopback
2

Do the same for IPv6 ... localhost resolves to both an IPv4 and IPv6 address, and v6 is preferred.

Edit 1:

ip6tables -I OUTPUT -o lo -p tcp --dport 5000 --match owner --uid-owner 1000 -j DROP
  • Thanks, I suspected something like this but I don't know how to do it for ipv6... -o lo in my iptables command should do the trick no ? – Nicolas Mauti Dec 9 '18 at 17:43
  • Try ip6tables -I OUTPUT -o lo -p tcp --dport 5000 --match owner --uid-owner 1000 -j DROP ;} – tink Dec 9 '18 at 17:49
  • 1
    It seems to work, thank you very much. I didn't know about ip6tables, I thought iptable worked for v4 and v6... – Nicolas Mauti Dec 9 '18 at 18:10
  • No worries, you're welcome. Feel free to accept my answer ;) – tink Dec 9 '18 at 18:12
  • I did but I haven't enough point to make the upvote visible... :) – Nicolas Mauti Dec 9 '18 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.