Score:0

How would you block a specific user from a specific IP and a specific port?

ma flag

Just curious here, no real use case...

The answer is probably /etc/hosts.deny but asking in case there are other way to do

Score:1
cn flag
Bob

You can use the netfilter "owner" module/extension to create the appropriate rules to match traffic from a specific user (on the Linux system where the user resides).

sudo iptables -I OUTPUT -m owner --uid-owner <USERNAME> -p tcp -m tcp -d destination-address --dport destination-port-number -j REJECT 

But once the IP traffic leaves the system there is no concept of "username/owner" in TCP/IP traffic anymore, packets only contain protocol, IP-address and port numbers and have no user identification that you could use as a reliable basis for firewall rules on a remote system or in an intermediate firewall.

The historic solution for that was the ident protocol and identd service (RFC 931 and descendant RFC 1413) running on the source IP-address of an incoming connection, which would return a username associated with a particular TCP connection. That is what allowed username based authentication in the hosts.[allow|deny] access controls. I don't know of anyone that either still supports or trusts the ident service anymore and even the RFC is quite explicit in section 6 on the security considerations "The Identification Protocol is not intended as an authorization or access control protocol", so don't go there.

ma flag
"Don't go there" - sold. Thank you for your insights
Score:1
th flag

you could install the UFW (Uncomplicated Firewall) package and then use the UFW in order to create some entries. When activating UFW all incoming traffic is being blocked & outgoing traffic is allowed by default. Before activating the UFW make sure to whitelist SSH connections in order to prevent locking you out from your server with sudo ufw allow 22. To enable your firewall you can use sudo ufw enable. To reload the firewall configurations you can enter sudo ufw reload.

In order to block a specific IPv4/6 Address you can create a ufw entry with this command: sudo ufw deny from [IPv4-Address] to any to block an IPv4 Address from your entire server.

But I dont exactly know about blocking a specifiy IPv4 Addresses & Port with UFW.

ma flag
Indeed, Ufw and Firewalld seem to be possible solutions too. Thank you
Kuezy avatar
th flag
No problem :) Happy to help
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.