date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,426,981,497,000 |
I am working with CentOS 7 OS hosting a set of docker containers.
By using a web browser I can reach a service on port 80 and I get back a response.
A bit of local knowledge helps me understand that the response comes from one of the docker containers.
However, I have a big problem: I can't seem to find a way for the ... |
Are you certain the docker host is listening on port 80? It might be redirected from port 80 to whatever port it is listening on using the built-in firewall.
If you are running IPTABLES, you could check this by using:
iptables -L -t nat
You would then see a chain named DOCKER which will tell you what redirects are in... | How can I get CentOS to correctly list open ports? |
1,426,981,497,000 |
I want to print 2 fields together, all open ports and the application using it. This is my command but it only prints the port numbers and still missing the program field:
netstat -lnt -u -p | awk '{print $4}' | sed 's/.*://' | sort -n | uniq
How can I modify this to print also the Program name as in "PID/Program nam... |
Shortened solution:
netstat -lpunt | awk -F' +|:+|/' '$5{print $5,$10}' | sort -n
-F' +|:+|/' - field separator (space(s), colon(s) or slash)
$5 - port number
$10 - program name
| Print ports with the application using it |
1,426,981,497,000 |
A strange situation. I started
telnet 0 8081
and lsof -i (run under root) doesn't list this connection, but netstat -n does.
Why can this be?
|
I just simulated your scenario and was able to get 8081 in both netstat and lsof. lsof -i displays 8081 as tproxy and so your grep might not be finding it. Try this with -P which shows the numerical ports:
lsof -i -P | grep 8081
| Why can `lsof -i` not show an open connection which `netstat -n` lists? |
1,426,981,497,000 |
I have two remote machines, I'm running a script on one of them.
There's some part of the script that should be running on the other one, then the script will continue in its further tasks/commands.
For some reasons I cannot establish a ssh-without-password connection, additionally, I'd not want any password prompts.
... |
to avoid SSH password promts:
sudo apt-get install sshpass
An alternative tool for package installation is dpkg
download the sshpass deb packet
and install it:
sudo dpkg -i sshpass_1.04-1_amd64.deb
pattern to use as follows:
sshpass -p mypassword ssh user@server
if needed to avoid sudo password promt:
ssh [email prote... | Connectivity between 2 remote Linux machines |
1,426,981,497,000 |
My remote Linux machine is able to ping an IP address on an internet, but the same action is unable to get the netstat report for that IP.
ping a.b.c.d
64 bytes from a.b.c.d: icmp_seq=1 ttl=64 time=0.509 ms
64 bytes from a.b.c.d: icmp_seq=2 ttl=64 time=0.249 ms
64 bytes from a.b.c.d: icmp_seq=3 ttl=64 time=0.273 ms
6... |
netstat doesn't accept an IP address argument. The only non-option argument is a delay, and that's not in all versions.
The command will
Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
for the local machine. It doesn't have any access to data about ... | Why is my Netstat not returning the desired output and just getting hung up? |
1,426,981,497,000 |
I have several problems:
some process is attempting to send data and the firewall is rejecting it at the rate it is sending it out
firewall logs flood the system (may need to rate-limit the logging)
lsof -i :port does not list the process, but there has to be something causing the packets to keep being sent. netstat... |
I couldn't resolve what was trying to connect, but what killed whatever process was trying to connect was simply ifconfig interface_name down.
| what process is listening on a given port |
1,426,981,497,000 |
I'm running an Embedded Linux system, whose kernel is 3.18.21, with some applications on top it on MIPS. When I run iptables & ip6tables on the Linux, such as the following:
iptables -A INPUT -p tcp --dport 80 -j DROP
ip6tables -A INPUT -p tcp --dport 80 -j DROP
The tcp port 80 is for http. Then I found that the ... |
iptables does not prevent applications from opening TCP or UDP ports (because that could cause the applications to crash). Instead, it will prevent incoming packets from reaching the actual ports. If applied to outgoing traffic, it can stop the matching packets from being actually sent.
If you use iptables ... -j DROP... | why iptables commands yield seemingly contradictory results on my embeded Linux? |
1,426,981,497,000 |
I want to see the state "syn_sent" of socket in realtime during the connection process
ss or netstat or any command
I have tried those commands, but all fail
watch netstat -tnaop|grep -i syn
ss -4 state syn
|
Solution found: this command works perfect
watch "ss -o state syn-sent '( dport = :https or sport = :https )'
this command also works fine
while true;do sleep 2s && netstat -napotep|grep SYN_SENT; done
| How to show the "syn_sent" socket state on Linux in realtime? |
1,426,981,497,000 |
With ss -tuiOp we can view extended stats for an outbound process, e.g.:
tcp ESTAB 0 0 192.168.68.108:32862 52.86.220.33:https
users:(("chrome",pid=13907,fd=44)) cubic wscale:12,7 rto:292 rtt:91.131/1.147 ato:40 mss:1288 pmtu:1500 ... |
The listening socket isn't the one transporting data! the moment a listening socket gets a connection request, the accept() system call can create a new connected socket. the listening socket doesn't transport any data, it just waits for connection requests. the listening socket and the data-transporting sockets are t... | View extended stats for listening ports (using ss?) |
1,426,981,497,000 |
On a recently installed Debian system I noticed that every boot, even with no networking, a folder and empty socket file are generated in /tmp/ssh-(random_letters)/agent.xxx.
On every boot the random letters assigned to the folder name and random numbers assigned to the socket file change.
On this system there is no V... |
All of those things look completely normal.
The SSH agent is started on login as part of your graphical desktop. Yes it doesn't care whether you have an Ethernet cable or not (nor should it). Yes it gets a random socket address every time.
The Charon socket will be listening whenever Charon (the strongSwan daemon) is ... | Random SSH Agent Generates on Boot in tmp Directory Even with Networking Disabled |
1,426,981,497,000 |
Learning about networks and trying to make sense of netstat output. This is the main confusion:
When I run the command, there are no known URLs. For example, I'm listening a Youtube streaming and was expecting to see UDP for the streaming. Am I expecting something that is not? Any help?
Slice of the output:
tcp ... |
Pretty much anything running in a web browser, like youtube, will use only HTTP and HTTP-based protocols like WebSockets. Web browsers forbid non-HTTP connections by websites for security reasons. So you're not usually going to see UDP, except possibly for HTTP-over-QUIC and HTTP 3.
Looking into the network monitor in... | Netstat doesn't show URLs while streaming from Youtube |
1,426,981,497,000 |
I am using Ubuntu 16.04, but I believe my question applies to many distros, such as Debian, CentOS, and Red Hat.
The manpage for netstat -l is:
Show only listening sockets. (These are omitted by default.)
and netstat -a is:
Show both listening and non-listening sockets. With the --
interfaces option, show interfa... |
Regarding the 2nd part of your question, netstat -plantu will show you only tcp and udp info, that is network connections established and listening ports. netstat -a will show you unix sockets also. That's lots of info, it's better to target what you need on the output.
If you run a recent distro, you can use ss inste... | Does netstat -l include anything that netstat -a does not have? |
1,426,981,497,000 |
From the following netsta we can see that Air_metal application is using port 50070 and established
# netstat -anp | grep :50070 | grep ESTABLISHED
tcp6 0 0 100.14.74.11:48148 100.14.74.12:50070 ESTABLISHED 29455/Air_metal
is it possible to check the time that Air_metal application start to using... |
check process number using the port ; then with process number you can go and read /proc//sched and get in milliseconds the stats.
root@zaphod:/tmp# netstat -anp | grep -i postgr
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 904/postgres
tcp6 0 0 :::5432 :::... | is it possible to check the time that l application start to using port and established |
1,426,981,497,000 |
On machine B, I remote access machine C
$ ssh -X t@C
$ echo $DISPLAY
localhost:10.0
How can I find/verify the mapping of $DISPLAY on C to $DISPLAY on B? Can it be done by the following command on C?
$ netstat -a | grep 6010
tcp 0 0 localhost:6010 0.0.0.0:* LISTEN
tcp6 ... |
"the mapping of $DISPLAY on C to $DISPLAY on B" what does that mean?
Clearly you grep out of something on C, so you only see sockets on C which involves "port num=6010". Other connection or listening socket on C are grep out.
You didn't see any connection before because there hasn't been any X client running and conn... | How can I find the mapping on `$DISPLAY` after `ssh -X`? |
1,426,981,497,000 |
If I have the following netstat output:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 127.0.0.1:21950 ESTABLISHED 2129/mysqld
tcp 0 0 127.0.0.1:38766 127.0.0.1:10033 TIME_WAIT -
If both... |
No, the local address is always the end of the connection that was opened by the process being described. In this case, the MySQL server process listens on port 3306, so that’s its local address in any established connection. The queues are also specific to the connection direction described.
For an established connec... | Are the 'Local Address' and 'Remote Address' netstat columns symmetrical for localhost? |
1,426,981,497,000 |
I am studying my listening services, and I am thinking how identify the type of git listening services so I can kill git the right one in the right situation and/or both.
The services are needed for git push and git pull or git clone [repos], working also for a git server (DopeGhoti).
Code where I do not understand ... |
"So many of them?" It's using precisely one, albeit on both the IPv4 and IPv6 interfaces.
Any service needs to be listening (or have a service aggregator such as xinetd listen by proxy) to some port or socket in order for incoming connections to be accepted.
In /etc/services, you can see git's port, 9418:
git ... | How to identify and kill git listening services here? |
1,426,981,497,000 |
I am trying to compile my own Linux for embededd devices, using the OpenWRT distribution. I am trying to get some Multicast information using the /proc/net/netstat interface but it is not found (normally this is available on my desktop).
If I am right this should be enabled in the kernel_menuconfig but I am not able t... |
After a while I have just returned to this issue, and finally solved it.
The problem is, that OpenWRT is pathcing the kernel source, and an extra option should be disabled, namely the CONFIG_PROC_STRIPPED. This is located in
(make) kernel_menuconfig -> File systems -> Pseudo filesystems -> [ ] Strip non-essential /pr... | /proc/net/netstat not found |
1,426,981,497,000 |
I have had a few issues with a server recently. So i just wanted to leave a window showing the unique and IP's of connected devices.
I have been using:
watch -n 5 "netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | sed 's/.*::ffff://' | sort | uniq -c | sort -nr"
Here is an example of the output when the formatt... |
I would try
... | awk '$5 ~ /:80$/ { split($5,A,":") ; if ( !u[A[1]]++ ) print A[1] ;} '
which should filter on distant IP on port 80.
no need to grep | awk | sed !!
$5 ~ /:80$/ filter fifth field ending in 80
!u[A[1]]++ is valid only once
split() will result in IP on A[1] (and port on A[2] ) (at least for pure IPV4... | Monitoring Server Connections - Netstat formatting issue |
1,379,330,544,000 |
My client is a MS Excel plug-in running on my laptop (client_machine1) that connects to a Solaris server (server1) to request some WebLogic Application running on port 28080.
bash-3.2$ set | grep SSH_CONNECTION
SSH_CONNECTION='<client_machine1 IP Address> 64134 <Server1 IP Address> 22'
bash-3.2$ netstat -a | grep <cl... |
If you do a netstat -a you get just the hostnames and names of services.
Example
$ netstat -a|head -20
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:sunrpc *:* ... | Why doesn't my client IP address appear in the netstat output? |
1,379,330,544,000 |
There is an old post about line truncation in netstat (Netstat output line width limit) but my question is a bit different.
I'm using netstat (net-tools 2.10) on Debian 12. My primary use is to list listening ports, e.g. netstat -tunlpWee I find the PID/Program name column to been too narrow. Is there a way to widen t... |
It seems that Program name column's width is hard coded[0] in netstat to 20 characters. So it is not possible to widen it without modifying the source itself.
Like you, I use ps to get broader program name. Ways to list full program names are discussed here [1].
[0] https://sources.debian.org/src/net-tools/2.10-0.1/ne... | Can you widen the columns in netstat, specifically "PID/Program name" ...? |
1,379,330,544,000 |
I was surprised to discover that two servers I'm maintaining are both able to listen on port 3000 in development at the same time.
With the first server running, netstat shows
▶ sudo netstat -nap tcp | grep 3000
tcp6 0 0 ::1.3000 *.* LISTEN
tcp4 0 0 1... |
Your assumption is correct for the first service. It listen on localhost and locahost6. About the second it seems it listen on the IPs of the host, different from above. But there is probability second also try to listen on localhost. You can check it by stop both and start only second one.
And if you permit me humble... | Can two servers bind the same port? |
1,379,330,544,000 |
with the following command I want to get which are the IP's that connected on my machine with port 8088
18.23.292.9 is machine that resource manager service is running on with port 8088
ss -tanp | grep 8088 | grep ESTAB
ESTAB 0 0 18.23.292.9:8088 118.2.291.2:52874 users:(("ja... |
I would do it the other way round.
I assume
you can connect to remote hosts,
and remote hosts is unix.
just run
ss -tanp | awk '$5 == "18.23.292.9:8088"'
on remote hosts.
assuming also that no NAT is set
| how to know what the process that connected to my machine VIA specific port |
1,379,330,544,000 |
Does GNU Screen have a server-client architecture model?
Is each Screen session a Screen client process?
Why can't I find out the Screen server process, but only its session processes i.e. client processes? (I suppose both Screen server and client processes contain a substring screen in their names up to cases)
$ ... |
Each Screen session is its own “server”; these are the “SCREEN” processes, and they are the processes which continue running when you detach from a session. The “client” is a “screen” process which connects to the corresponding session and allows you to interact with it; these are short-lived (relatively speaking), an... | How can I find out the Screen server process? |
1,379,330,544,000 |
I am struggling to close these ports which seem to be backdoors -- or at least I have never opened and used them. How can I close or shutdown nc and close these ports?
netstat -lntup | grep nc
ps-ef
|
After further investigation through chat, the problem was identified with a specific crontab on OP's system. This was identified using the parent PID of the nc process, which showed the following connection:
nc -l -p 45454 -e /usr/sbin/link -> /bin/sh -c nc -l -p 45454 -e /usr/sbin/link -> /usr/sbin/CRON -f
The user a... | How to close nc port in Debian 9? |
1,379,330,544,000 |
I'm not able to detect incoming connections from Nextcloud sync clients via netstat on my server.
I have a server in my LAN, running Nextcloud with MySQL in docker containers. I use multiple Nextcloud Clients (Linux, macOS and iOS), everything is working fine.
I want to check if clients are connected to my server on h... |
The connections are probably DNATed to the containers. That means the host is now acting as a router between "outside" and the containers. netstat will not display those connections. You will need additional tools for the missing flows.
One such tool is conntrack, which queries conntrack about tracked connections. Usi... | Monitor Nextcloud connections with netstat |
1,379,330,544,000 |
How is it possible that netstat -a | grep 8081 shows this:
localhost.8081 *.* 0 0 49152 0 LISTEN
*.8081 *.* 0 0 49152 0 LISTEN
I don't really understand which means the second entry.
UPDATE_1: I've checked that two different processes a... |
I did the following experiment to illustrate my comment above. I use the netcat command to implement two simple TCP servers. My secnario differs from yours a bit in that I explicitly bind to the public IP instead of *:8081
# Terminal 1
$ nc -kl 127.0.0.1 24482
In a separate terminal:
# Terminal 2
$ nc -kl <public_i... | Two local address listening on same port? |
1,379,330,544,000 |
If I ssh root@server -R 5901:localhost:5900 and netstat -an I get:
Active Internet connections (servers and established) │
Proto Recv-Q Send-Q Local Address Foreign Address State │
tcp 0 0 127.0.0.1:5901 0.0.0.0:* ... |
In IPv6 terminology, ::1 is the loopback address (e.g. 127.0.0.1 in IPv4 terminology).
It is essentially 0:0:0:0:0:0:0:1 (or more precisely, but uninterestingly, 0000:0000:0000:0000:0000:0000:0000:0001) with all the 0's collapsed down into ::1. It is functionally equivalent to the IPv4 127.0.0.1 and performs the same... | reading the output of netstat for tcp |
1,379,330,544,000 |
I have some open ports on my laptop but netstat is not reporting which PID/Program is associated with them:
$ netstat -tulpn
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local ... |
Hint:
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Try running netstat using sudo, i.e. sudo netstat ...
| Open ports with no associated PIDs |
1,379,330,544,000 |
I have a DD-WRT router with an OpenVPN service configured. I'd like to send only certain source IP's over the vpn connection.
I believe my current routing table (as seen with
netstat -rn) sends all my traffic over the vpn on interface tun1. From what I understand the routing table is a "fall through" table so in thi... |
I understand the routing table is a "fall through" table
Not really. The routing table is ordered from "most specific route" to "least specific route". Your default route is via br0, and is defined as the route of last resort because there is no netmask (i.e. genmask is 0.0.0.0).
because the 1st entry is 0.0.0.0 al... | Routing Configuration sending some traffic over VPN |
1,379,330,544,000 |
When trying to see port clashes within my system, many websites online recommend using /etc/services or ss -tunl to see port info
I am noticing /etc/services is providing different information to -ss on most occasions.
Output comparison examples
sudo cat /etc/services
ftp 21/udp
ftp 21/s... |
The file /etc/services only provides number to name mapping for ports, and has nothing to do with what ports ss lists. Additionally, the names in this file are common uses for the ports, not what the port is actually used for on your system, as any program (with sufficent permissions) can open any port for any purpos... | Where does ss command gather its data for ports etc |
1,379,330,544,000 |
If I check how many connections serverA (192.168.1.1) has open to serverB (192.168.2.1), I get the following response:
[username@serverA ~] $ netstat -n | grep 192.168.2.1
tcp 0 0 192.168.1.1:51846 192.168.2.1:10001 ESTABLISHED
tcp 0 0 192.168.1.1:50872 192.168.2.1:10001 ESTABLI... |
This was solved by a patch release for the application server in use.
| Running netstat on 2 servers checking connections to the other one shows mismatch in number of connections |
1,379,330,544,000 |
I'm testing my linux server with the command netstat -i.
I just want to know what enp2s0f0 means. Each time that I execute netstat -i, its RX-OK and TX-OK always increase. What does this mean?
|
enp2s0f0 - is your primary network interface. About the convention of naming network interfaces you can read on wiki.
The RX-OK/ERR/DRP/OVR columns give statistics about the packets that have been received by the interface. OK stands for packets correctly received.
TX-OK stands for packets correctly transmitted respec... | Why do RX-OK and TX-OK increase |
1,379,330,544,000 |
My networking skills are quite poor and I am trying to understand the following netstat -ton meaning.
We have redis server and a client with a thread connecting to it via PUB/SUB. The client SUBSCRIBE to a Redis channel.
This, I guess, creates a long lived TCP link between both and the server sends data to the client... |
It seems to me, that problem is within your client, because Recv-Q for established connections is the count of bytes not copied by the user program connected to this socket. It means, your application does not read data from socket.
| Stalled TCP connection with data in RecvQ and ESTABLISHED off |
1,379,330,544,000 |
I want to use command line to show only the port numbers after ":" only
This is what I'm trying to do
sudo netstat -ant |grep LISTEN|grep :|sort -n|cut -c 45-
It shouldn't list any tcp6 info
|
With sed:
sudo netstat -4tln | sed '1d;2d;s/[^:]*:\([0-9]\+\).*/\1/' | sort -n
| how to show port numbers that are listening for the incoming connections under TCPv4? |
1,379,330,544,000 |
I need port 3000 free for my dev work. But it's being used by grafana-server, that I don't remember ever installing. We do use it within our company so perhaps at some point it has been added to system somehow.
Anyway, so I use this command sudo netstat -lepunt | grep 3000 to get the process that is on port 3000.
The... |
Credit goes to user OweH_OweH on reddit.
systemd restarts it, because grafana-server.service has Restart=on-failure in it and by sending the process SIGKILL you trigger that failure state. If you just use the normal kill PROCID_HERE command it will terminate normally and not be restarted.
So I shouldn't have being a... | Port 3000 is always being hogged by grafana-server |
1,487,136,316,000 |
The question is pretty much already in the title:
Can nftables and iptables/ip6tables rules be applied at the same time? If so: what's the order of precedence?
The reason I ask is this: plenty of tools - especially from the realm of containerization - still rely on iptables and ip6tables to add rules and make containe... |
It is possible to use the kernel’s iptables and nftables simultaneously, but it requires some attention. The order in which the rules are applied is determined by the hook priority; legacy iptables default is 0, so an nft hook can be set to priority -1 if it should apply before iptables, or 1 if it should apply afterw... | Can nftables and iptables/ip6tables rules be applied at the same time? If so: what's the order of precedence? |
1,487,136,316,000 |
I am trying to apply below nftables rule which I adopted from this guide:
nft add rule filter INPUT tcp flags != syn counter drop
somehow this is ending up with:
Error: Could not process rule: No such file or directory
Can anyone spot what exactly I might be missing in this rule?
|
You're probably missing your table or chain.
nft list ruleset
will give you what you are working with. If it prints out nothing, you're missing both.
nft add table ip filter # create table
nft add chain ip filter INPUT { type filter hook input priority 0 \; } # create chain
Then you should be able to add your rule t... | nftables rule: No such file or directory error |
1,487,136,316,000 |
When configuring a chain in nftables, one has to provide a priority value. Almost all online examples set a piority of 0; sometimes, a value of 100 gets used with certain hooks (output, postrouting).
The nftables wiki has to say:
The priority can be used to order the chains or to put them before or after some Netfilt... |
UPDATE: iptables-nft (rather than iptables-legacy) is using the nftables kernel API and in addition a compatibility layer to reuse xtables kernel modules (those described in iptables-extensions) when there's no native nftables translation available. It should be treated as nftables in most regards, except for this que... | When and how to use chain priorities in nftables |
1,487,136,316,000 |
I am moving from iptables to nftables. I have a basic questions about the packet processing order in nftables.
Since one can create multiple tables of same type, say inet, and also chains can be created inside each table with different or the same priority, what will be the processing order.
For example, if I create f... |
The ordering in the example will be undefined, but both chains will be traversed (unless for example the packet gets dropped in the first chain seen).
Netfilter and the Network/Routing stack provide the ordering
Here's the Packet flow in Netfilter and General Networking schematic:
While it was made with iptables in m... | Packet processing order in nftables |
1,487,136,316,000 |
How can i do this in a single line?
tcp dport 53 counter accept comment "accept DNS"
udp dport 53 counter accept comment "accept DNS"
|
With a recent enough nftables, you can just write:
meta l4proto {tcp, udp} th dport 53 counter accept comment "accept DNS"
Actually, you can do even better:
set okports {
type inet_proto . inet_service
counter
elements = {
tcp . 22, # SSH
tcp . 53, # DNS (TCP)
udp . 53 # DNS (UDP)
}
And then:
... | How to match both UDP and TCP for given ports in one line with nftables |
1,487,136,316,000 |
Use case: I have a home router using iptables today. I'm researching converting over to nftables, as it looks to be much more manageable for a lot of rules.
One thing I have setup today under iptables is a 'country-block' ipset which contains country CIDR blocks that covers the majority of random port probe/hack attem... |
I received a response from the nftables developers after asking on their mail list. The short answer is that referencing sets in another table is not possible.
However, I was at least able to store my sets in a separate file and bring them in via an @include. This makes my ipsets more manageable instead of having to p... | nftables ip set multiple tables |
1,487,136,316,000 |
I've been on CentOS 7 for a long time and was used to building my custom iptables configurations on a variety of both personal and business boxes.
I've recently started working with CentOS 8 and learned of the move from iptables to nftables and so I was able to rewrite my rulesets and got everything up and running. ... |
I think the answer is fairly straightforward. First, you have done exactly the right thing...
Firewalld is a pure frontend. It's not an independent firewall by itself. It only operates by taking instructions, then turning them into nftables rules (formerly iptables), and the nftables rules ARE the firewall. So you hav... | CentOS 8 firewalld + nftables or just nftables |
1,487,136,316,000 |
Given a host that is in an unknown state of configuration, I would like to know if there is an effective way of non-interactively determining if the firewall rule set in place is managed by iptables or nftables.
Sounds pretty simple and I've given this quite a bit of thought, but haven't come back with a meaningful an... |
A variant of this problem was addressed recently in Kubernetes, so it’s worth looking at what was done there. (The variant is whether to use iptables-legacy or iptables-nft and their IPv6 variants to drive the host’s rules.)
The approach taken in Kubernetes is to look at the number of lines output by the respective “s... | Check whether iptables or nftables are in use |
1,487,136,316,000 |
I have a number of rules in table mytable chain mychain:
> sudo nft -a list table mytable
table ip mytable { # handle 8
chain mychain { # handle 1
type filter hook input priority filter; policy accept;
tcp dport 5550 accept # handle 18
tcp dport 5551 accept # han... |
There are still some errors lurking in the nftables wiki. The actual syntax is quite logical:
to remove everything
nft flush ruleset
to empty a table (with ip as family by default if not specified). Eg for my table
nft flush table mytable
to delete a table (which also empties it first). Eg for mytable
nft delete ta... | nftables remove all rules in chain |
1,487,136,316,000 |
I have been reading for a while now.
What I understood is:
nftables is the modern Linux kernel packet classification framework. nftables is the successor to iptables. It replaces the existing iptables, ip6tables, arptables, and ebtables framework.
x_tables is the name of the kernel module carrying the shared code por... |
My view is that iptables, ip6tables, ebtables and arptable is a frontend tool-set to Netfilter.
They are a user-space tool-set that format and compile the rules to load them in the core Netfilter that runs in the kernel. You can find all the kernel parts of Netfilter in your modules directory ls /lib/modules/$(uname -... | What is the relationship or difference among iptables, xtables, iptables-nft, xtables-nft, nf_tables, nftables |
1,487,136,316,000 |
I have created a net-filter table. I have it in a script. I can not get this script to always load. If I flush/delete the table, then it does not work, if the table does not exist. If I do not flush/delete then it merges the old and new rules.
How do I flush/delete if the table exists?
#!/usr/sbin/nft -f
flush table ... |
First declare an empty table. If the table already existed, it doesn't throw an error nor alter its content: nothing happens. If it didn't exist, the empty table was just created. Now that it exists in all cases, it can be deleted. All this can be done in the same ruleset.
So, declare the table without chain nor rules... | nftables: flush/delete when changing or creating new table |
1,487,136,316,000 |
I'm trying to set up a firewall on my own desktop (currently I'm tinkering with a Fedora 29 virtual machine). I would like to have it on the "deny-everything-by-default" basis. Almost immediately I decided to disable and mask the firewalld.service, since firewalld had no way to drop the outgoing packets, except by usi... |
For the question per se, these are the last two questions from the original post:
How can I reliably use nft without iptables rules interference?
Or should I simply use iptables and remove nft?
this is what the nftables wiki says:
What happens when you mix Iptables and Nftables?
How do they interact?
nft Empt... | How to prevent iptables and nftables rules from running simultaneously? |
1,487,136,316,000 |
I have two docker containers running on my machine where a very restrictive nftables configuration is active. I'd like to keep it that way but whitelist access to the docker containers from outside.
The containers open ports 80 and 6200. The docker service is started with iptables disabled.
Below is the current firewa... |
While the problem might appear simple, it's nothing but. Having Docker around always imposes several challenges to other parts in the system dealing with networking. Once nftables gets more widely adopted and gets directly used by Docker in the future, and especially once Docker stops using br_netfilter, things might ... | nftables whitelisting docker |
1,487,136,316,000 |
On Debian 10 buster I am having problems with docker containers unable to ping the docker host or even docker bridge interface, but able to reach the internet.
Allowing access as in related questions here, doesn't fix it in my case.
Seems iptables/nftables related, and I can probably figure out what to do, if I could ... |
You can use nftrace to trace packet flows. It's very verbose but doesn't go to kernel logs but instead is distributed over multicast netlink socket (ie if nothing listens to them, traces just go to "/dev/null").
If you really want to trace everything, trace from prerouting and output at a low priority. Better use a se... | How to properly log and view nftables activity? |
1,487,136,316,000 |
Is it possible to have an nftables map which maps port to ipv4_addr:port, where port and ipv4_addr:port have different TCP port numbers? For example, I want to dnat all incoming packets on port 80 to a container running a web server on port 8080 (purely with nftables). This is possible using two maps and two map looku... |
As usual nftables is a moving target. This feature appeared in nftables 0.9.4 released on 2020-04-01:
NAT mappings with concatenations. This allows you to specify the address and port to be used in the NAT mangling from maps, eg.
nft add rule ip nat pre dnat ip addr . port to ip saddr map { 1.1.1.1 : 2.2.2.2 . 30 }
... | nftables map `port` to `ip:port` for DNAT |
1,487,136,316,000 |
I want to create a dynamic blacklist with nftables. Under version 0.8.3 on the embedded device I create a ruleset looks like this with nft list ruleset:
table inet filter {
set blackhole {
type ipv4_addr
size 65536
flags timeout
}
chain input {
type filter hook input priority 0; policy drop;
ct st... |
The hydra tool connects concurrently multiple times to the SSH server. In OP's case (comment: hydra -l <username> -P </path/to/passwordlist.txt> -I -t 6 ssh://<ip-address>) it will use 6 concurrent threads connecting.
Depending on server settings, one connection could typically try 5 or 6 passwords and taking about 1... | Create dynamic blacklist with nftables |
1,487,136,316,000 |
I have an OpenWRT gateway (self-built 19.07, kernel 4.14.156) that sits on a public IP address in front of my private network. I am using nftables (not iptables).
I would like to expose a non-standard port on the public address, and forward it to a standard port on a machine behind the gateway. I think this used to ... |
You are not translating the port number. When the external connection is to port 1234, this is not a problem. But when it is to 4321, the dnat passes through to port 4321 on the internal server, not port 1234. Try
tcp dport { 1234, 4321 } log prefix "nat-pre " dnat 172.23.32.200:1234;
You do not need to translate ... | Port forwarding & NAT with nftables |
1,487,136,316,000 |
I have the below iptable rule in /etc/iptables/rule.V6 and /etc/iptables/rule.V4
-4 -A INPUT -p icmp -j ACCEPT
-6 -A INPUT -p ipv6-icmp -j ACCEPT
when I tried to restart the netfilter-persistent, it internally calls the iptables-restore and ip6tables-restore.
ip6tables-restore failed because it couldn't understand th... |
You are most certainly running iptables over nftables, as this is the default on Debian buster. To confirm this is the case, check for (nf_tables):
# ip6tables-restore --version
ip6tables-restore v1.8.2 (nf_tables)
Now in the ip6tables manual, there always has been:
-4, --ipv4
This option has no effect in iptable... | ip6table-restore failed in Debian buster/sid |
1,487,136,316,000 |
It is simple to list all open ports and its services with firewll-cmd:
sudo firewall-cmd --list-all
How can get the list with nftables?
|
Here's my nftables cheat sheet:
Load rules: nft -f /etc/sysconfig/nftables.conf (this will append them to the existing ones, so flushing first might be required)
Watch rules: nft list ruleset
Reset rules: nft flush ruleset
Speaking of your request:
nft list ruleset | grep dport
Since tables and chains can be called ... | How to list all ports and service with nftables? |
1,487,136,316,000 |
We have a Debian Buster box (nftables 0.9.0, kernel 4.19) attached to four different network segments. Three of these segments are home to devices running Syncthing, which runs its own local discovery via broadcasts to UDP port 21027. The devices thus can't all "see" each other as the broadcasts don't cross segments; ... |
It's still possible to use nftables in the netdev family (rather than ip family) for this case, since only ingress is needed (nftables still doesn't have egress available). The behaviour of dup and fwd in the ingress hook is exactly the same as tc-mirred's mirror and redirect.
I also addressed a minor detail: rewrite ... | nftables: duplicate broadcast packets between segments |
1,487,136,316,000 |
I have problems understanding verdict statements in nftables. From man nft, or from here, shortly below the heading "Verdict statement", we read the following:
accept and drop are absolute verdicts --- they terminate ruleset evaluation immediately.
but then, in the next sentence (emphasizing mine):
accept: Terminat... |
I think what they mean is that the accept will end that specific hook, but another may stop it. For example, looking at this illustration, if the Forward Hook were to accept, but then the Postrouting Hook were to drop, that would satisfy your latter quote because it is "another hook."
(This is speculation because I on... | In nftables, is the verdict statement "accept" final or not? |
1,487,136,316,000 |
Given the following diagram, is it possible to route traffic through the linux kernel like this? I wish to simulate an exact copy of the devices outside of my "inner" network, with the same IP-ranges whilst enabling the inner and outer devices to communicate with each other without knowing that the other has the same ... |
Topology
We start by configuring the network interfaces on middleman. I'm assuming that either you're logged in on the system console or you have access via an interface that's not involved in either the inner or outer networks. For the purpose of this answer, we're going to assume that interface middleman-eth0 on mid... | Routing traffic to virtual copy of network without namespaces |
1,487,136,316,000 |
I have two systems that are connected over Ethernet and one system has a WiFi radio which provides internet access.
In this diagram sys#2 has the WiFi radio
sys#1 <---> Ethernet <---> sys#2 <---> wifi <---> internet
sys#2 routes packages from Ethernet (interface eth0) out to wifi (interface wlan0). sys#2 connects t... |
Using nft, to drop all ethernet frames which are received from network interface eth0 and do not have source address of 00:00:5e:00:53:00:
nft add rule filter input iif eth0 ether saddr != 00:00:5e:00:53:00 drop
iptables allows similar filtering with mac extension:
iptables -A INPUT -i eth0 -m mac ! --mac-source 00:0... | Is it possible to filter/drop packets by MAC using nftables |
1,487,136,316,000 |
I would like to e.g. block certain traffic between 00:00 and 04:00. Is this possible in nftables?
(Obviously I can just set a cron job that changes the config at these times - but I would like to know if there is a nftables "native" way of achieving this.)
|
There are recent patches allowing to do just that, but they are not yet available in any release.
Here are the relevant patches (but they are part of series, they would probably not be enough te be applied by themselves).
linux kernel:
[v5,2/2] netfilter: nft_meta: support for time matching
libnftnl (userland low leve... | How do you filter packets differently based on time of day in nftables? |
1,487,136,316,000 |
I have a Fedora 31 system on which I am using iptables-nft. I need this because there is still a bunch of software that expects the legacy iptables command line tools. This means that my nftables configuration has the corresponding set of tables to match the legacy configuration:
table ip filter
table ip nat
table ip... |
After some discussions on the #netfilter irc channel, it turns out that things are function "as designed". It is not possible for one chain to provide broader access (in the form of accept rules) than that provided by a chain with a reject (or drop) rule.
An accept verdict is only valid in the chain in which it occurr... | Using custom tables in nft |
1,487,136,316,000 |
I have a physical network with a Linux server (Ubuntu 16.04, kernel 4.13) and several gadgets on it. Each gadget has the same unchangeable static IP, e.g. 192.168.0.222/24. I would like to communicate with all these gadgets via an arbitrary IP protocol (e.g. ICMP ping or a custom UDP protocol)
Fortunately I have a ma... |
I was able to achieve this with the following nftables ruleset (I had to build nft from source as v0.5 which ships with Ubuntu 16.04 doesn't support packet field mangling) :
table ip mytable {
chain prerouting {
type filter hook prerouting priority -300; policy accept;
iifname "... | nftables / iptables rules to rewrite source IP by interface |
1,487,136,316,000 |
I am configuring a REDIS server and I want to allow connections only from a set of specific IP addresses.
This is a Debian 10 server, and the recommended framework to use is nft, which I haven't used in the past.
The default ruleset is this:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
... |
In case someone else stumbles upon the same issue, my main problem was that I was using rules in the incorrect order.
I was adding a drop rule before the accept rule, and this seems to work the other way around.
This is a sample rule for dropping all IP addresses except 2:
ip saddr 1.1.1.1 tcp dport 6379 accept
ip sad... | nftables allow redis only from specific IP addresses |
1,487,136,316,000 |
I am trying to set up a port forwarding proxy using a Raspberry Pi 4 with NFTables. I want to duplicate the simple port forwarding capabilities of a cheap home nat router. This a component of a larger remote admin application I am working on.
I can get it to redirect ports on the host itself using redirect. But I cann... |
Your current setup doesn't work simply because forwarding is disabled, despite:
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
because of the type filter hook forward chain set to policy drop:
chain forward {
type filter hook forward priority 0; policy drop;
}
If you want to restrict forwa... | Port forwarding not working with "policy drop" |
1,487,136,316,000 |
What I am doing is quite simple, I use port forwarding and enable masquerading on the POSTROUTING chain:
table inet nat {
chain prerouting {
type nat hook prerouting priority -100; policy accept;
ip daddr 198.51.100.105 counter dnat to 10.8.0.105 comment "host.example.com"
}
chain post... |
Remarks and adjustments (probably caused by obfuscation):
I'll assume the WireGuard peer uses 10.8.0.105 instead of 10.8.0.107, to match the nftables ruleset.
233.252.0.0 would cause problems in a simulation (especially on peer) because it's a multicast address. I'll use 192.0.2.233 below (with no network relation to... | nftables, masquerade: packets go through wrong outbounding interface |
1,487,136,316,000 |
I have this rule for iptables
iptables -I INPUT 1 -i eth0 -p tcp -s 192.168.178.20 --dport 8201 -j REJECT
I was looking for how to translate rules tutorials but couldn't find them.
How do I create that rule with nftables? Or is the syntax the same?
|
From nftables wiki:
Since June 2018, the old xtables/setsockopt tools are considered legacy. However, there is support to use the iptables/ip6tables/arptables/ebtables old syntax with the nf_tables kernel backend. This is described with further details in the Legacy xtables tools wiki page.
You can use iptables-nft ... | Translate firewall rule from iptables to nftables |
1,487,136,316,000 |
I'm looking to apply firewall rules on egress to control DHCP output from a Docker container. I don't want the DHCP container to share the host's network stack as adding CAP_NET_ADMIN effectively gives the container control of the network stack.
I notice here that an egress hook was added to netfilter in kernel 5.7 (u... |
Actually nftables's egress hook was added in kernel 5.16, and improved support (fwd) in 5.17.
There were several attempts earlier, and one of them was NACK-ed at the same time it was initially committed, making it appear in Kernel Newbies for version 5.7, and apparently even nftables' wiki has it wrong by linking to K... | NFTables Egress Hook? |
1,487,136,316,000 |
What happened during these logs entry events below?
Nov* 8 09:37:12 kernel: [10967.520783] New Input packets: IN=lo OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:08:00 SRC=192.168.1.2 DST=192.168.1.2 LEN=85 TOS=0x00 PREC=0xC0 TTL=64 ID=6855 PROTO=ICMP TYPE=3 CODE=1 [SRC=192.168.1.2 DST=192.168.1.1 LEN=57 TOS=0x00 PREC... |
Nov* 8 09:37:12 kernel: [10967.520783] New Input packets: IN=lo OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:08:00 SRC=192.168.1.2 DST=192.168.1.2 LEN=85 TOS=0x00 PREC=0xC0 TTL=64 ID=6855 PROTO=ICMP TYPE=3 CODE=1 [SRC=192.168.1.2 DST=192.168.1.1 LEN=57 TOS=0x00 PREC=0x00 TTL=64 ID=60616 DF PROTO=UDP SPT=49662 DPT=53 ... | Understanding nftables logs |
1,487,136,316,000 |
In iptables it was possible to use eth+ as interface name to match any interface starting with eth (or as a more practical example this also worked to match virbr+ and veth+, i.e. the + seemed to have the effect of a * in shell globs).
Does nftables offer a similar facility to match interface names? How do I use it?
|
Yes the usual wildcard character * is nft's equivalent of iptables' +. The man page was not documenting this (relatively old) feature until recently.
From a recent enough nft man page:
Like with iptables, wildcard matching on interface name prefixes is
available for iifname and oifname matches by appending an asteris... | Is there a sort of wildcards in nftables? |
1,487,136,316,000 |
I wanted to add the rule arp saddr ip 192.168.2.1 counter accept to my Nftables firewall. When reading the config-file with sudo nft -f /etc/nftables2.conf, I get the error-message
/etc/nftables2.conf:26:21-15: Error: syntax error, unexpected saddr
arp saddr ip 192.168.2.1 counter accept
... |
Your ruleset is correct. But your nftables version is slightly too old. Here's the announce including your example:
[ANNOUNCE] nftables 0.9.1 release:
Hi!
The Netfilter project proudly presents:
nftables 0.9.1
This release contains fixes and new features, available up with Linux
kernels >= 5.2.
[...]
ARP send... | nftables Error: syntax error, unexpected saddr |
1,487,136,316,000 |
A few months ago, I migrated the firewall of a debian laptop from iptables to nftables, using debian's recommended procedure, and all seems to have been fine. Now, months later, I'm scrutinizing the rule-set created by that migration procedure, trying to learn the nftables syntax, and see what seem to be several count... |
No, the explanation is much simpler: the counter statement has optional arguments packets and bytes which display the number of packets and bytes counted by the counter when a packet reached the rule where it was. Without filter before the counter, any packet (including on loopback) will thus increase the values so it... | firewall: nftable counter rules |
1,487,136,316,000 |
Current system:
Distro: Ubuntu 20.04
kernel: 5.4.0-124-generic
nft: nftables v0.9.3 (Topsy)
I am new and learning nftables, Here is my nft ruleset currently:
$sudo nft list ruleset ... |
The wiki says what you tried is not yet implemented: You have to obtain the handle to delete a rule. The example is:
$ sudo nft -a list table inet filter
table inet filter {
...
chain output {
type filter hook output priority 0;
ip daddr 192.168.1.1 counter packets 1 bytes 84 # hand... | How do I delete a specific element in a chain in nftables? |
1,487,136,316,000 |
I have a WireGuard server as the edge router. Forwarding all http traffic to my web server.
Everything works fine but there is a problem. The web server cannot access itself through the WireGuard public IP address. On the web server computer, I cannot use the web browser to access my website.
I found that daddr based ... |
This is a case of NAT loopback handling.
Currently the WireGuard server ("WGS") redirects only from eth0, so nothing will happen with traffic received from wg0.
On should redirect on WGS incoming traffic to ports 80,443 intended for its own public IP address. But there's a catch: how to guess at a pre-routing step tha... | Web server cannot access itself through public ip address on nftables port forwarding |
1,487,136,316,000 |
There is only one table on the server - "nat" and it contains only two chains: "prerouting" and "postrouting". IP forwarding is enabled. I'm trying to set more specific conditions for the source nat rule. When I set the classic rule :
nft add rule nat postrouting ip saddr 192.168.1.0/24 oif eth0 snat 1.2.3.4
everythi... |
This feature also requires kernel >= 5.5 for adequate netfilter support. Description in kernelnewbies.org:
Linux 5.5 was released on 26 Jan 2020
[...]
netfilter
Support iif matches in POSTROUTING commit
From the commit:
netfilter: Support iif matches in POSTROUTING
Instead of generally
passing NULL to NF_HOOK_... | How to set hard conditions for source nat rules in nftables? |
1,487,136,316,000 |
I'm trying to get some traffic to go through a VPN and other traffic to not do so.
Packets with a given fwmark are supposed to go to my default interface (wlo1), and all other traffic to a tunnel interface (tun0, using OpenVPN) in the main table. I have added this rule in nftables:
table ip test {
chain test {
... |
When a packet is emitted, there's a routing decision made: this decision chooses the outgoing interface and the matching source IP address to use.
When the route/output chain sets a mark, it triggers a reroute check, as seen in this schematic (which was made for iptables in mind but is totally usable for nftables). Th... | Route traffic in a cgroup outside a VPN tunnel |
1,651,155,404,000 |
Using sets in nftables is really cool. I am currently using a lot of statements like these in my nftables.conf rulesets:
iifname {clients0, dockernet} oifname wan0 accept \
comment "Allow clients and Docker containers to reach the internet"
In the rule above {clients0, dockernet} is an anonymous (inline) set of i... |
By searching in the source for version 0.9.0:
static const struct datatype *datatypes[TYPE_MAX + 1] = {
[...]
[TYPE_IFINDEX] = &ifindex_type,
[...]
[TYPE_IFNAME] = &ifname_type,
};
and then looking for where they are defined:
const struct datatype ifindex_type = {
.type = TYPE_IFINDEX,... | How do I create a named set of interfaces by name in nftables? |
1,651,155,404,000 |
I have two virtual machines (router and client) ubuntu server 18 04, the router is the gateway for the client.Nftables are installed on the router and a NAT table is created with two chains pre and postrouting with a rule for the client.
table ip nat {
chain prerouting {
type nat hook prerouting priority -... |
In addition to the Linux network stack, there's an additional "stack" intended to alter behavior but that is kept as much as possible separate from the network stack: Netfilter. This facility allows clients (still in the kernel) to hook into it to intercept packets at various strategic places during its life in the ne... | How to reset sessions in nat table? |
1,651,155,404,000 |
I want to close port 80 in localhost.
sudo nft add rule inet filter input tcp dport 80 drop
To check with nmap:
sudo nmap -p 80 127.0.0.1
Starting Nmap 7.70 ( https://nmap.org ) at 2021-05-02 05:16 EDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
PORT STATE SERVICE
80/tcp open htt... |
The order of the rules is important: if an earlier rule matches a packet and says that it should be accepted, a later rule cannot override that decision. You must either take care to insert the rule blocking the traffic before any rule that will accept it, or delete a previous rule that is currently accepting the traf... | Why can't close the port 80 with nftables? |
1,651,155,404,000 |
I installed nftables on a new Debian 12 (on AWS EC2). I am connected to the instance (the external EC2 IP) over port 22/tcp. I mention EC2 because maybe they do weird tricks. I then installed nftables with:
sudo apt install nftables
sudo systemctl enable nftables
sudo systemctl start nftables
At this poin... |
By default nftables does not create any chains meaning every packet is accepted and allowed.
You have created three base chains input forward and output
The default policy if not specified for these is accept which is the same as not having any chains.
To block any packets by default you need to set default action pol... | Does nftables allow port 22 or other ports by default? |
1,651,155,404,000 |
I'm trying to implement a way to prevent network scans from my notebook. One of the things I want is to allow arp request to specific hosts, like my gateway.
I added some rules using arptables and they seem to work (at first)
arptables -A OUTPUT -d 192.168.1.30 -j DROP
arptables -A INPUT -s 192.168.1.30 -j DROP
This... |
I'll complete OP's setup: address 192.168.1.38/24 on eth0 and a gateway (not really needed) 192.168.1.1. If the setup uses Wifi rather than actual Ethernet, the first method (bridge) won't be available without additional efforts (probably easy if Access Point, very difficult to impossible if not AP).
nmap uses a pac... | arptables not working with nmap |
1,651,155,404,000 |
I use WireGuard as a secure communication channel between two servers in different DCs to hide the existence of the end server (server B).
I use nftables as a firewall management tool.
From public server A, the traffic is forwarded keeping the IP address (necessary for the application).
The destination server B receiv... |
The required information to reply correctly: "From which interface did the initial packet come from?" is lost when a different packet is seen in reply coming from a network interface. A way to memorize it and reuse it in replies is needed. Here it is: conntrack which memorizes a list of all currently tracked connectio... | Forwarding traffic back through WireGuard (Setting dnat for oif wg0, after processing the application) |
1,651,155,404,000 |
I have the following in nftables.conf:
table inet nat {
set blocked {
type ipv4_addr
}
chain postrouting {
type nat hook postrouting priority 100; policy accept;
ip daddr @blocked counter drop;
oifname "ppp0" masquerade;
... |
The nat hook (as all other hooks) is provided by Netfilter to nftables. The NAT hook is special: only the first packet of a connection is traversing this hook. All other packets of a connection already tracked by conntrack aren't traversing any NAT hook anymore but are then directly handled by conntrack to continue pe... | nftables Named Set Update Delay |
1,651,155,404,000 |
My pppoe client automatically adds an iptables rule iptables -t mangle -o "$PPP_IFACE" --insert FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:65495 -j TCPMSS --clamp-mss-to-pmtu from /etc/ppp/ip-up.d. However, this rule in nftables looks like
table ip mangle {
chain FORWARD {
type filter ho... |
Explanation
the rule set through iptables-nft is using xtables kernel modules (here: xt_tcpmss and xt_TCPMSS) through the nftables kernel API along a compatibility layer API, even if xtables was initially intended for (legacy kernel API) iptables.
Native nftables cannot use xtables kernel modules by design: whenever ... | Why MSS clamping in iptables(-nft) seems to take no effect in nftables? |
1,651,155,404,000 |
I tried this:
iptables -F
ip6tables -F
sudo nft list ruleset > /etc/nftables.conf
sudo service netfilter-persistent save
But after reboot when I run
nft list ruleset
I see nothing. I think that netfilter-persistent doesn't see my file with rules. I use Debian Buster.
|
By itself netfilter-persistent does nothing, it's a plugin framework only. It does not read /etc/nftables.conf in particular. You should have nftables plugins installed under /usr/share/netfilter-persistent/plugins.d for it to work with nftables. However, I don't think such plugins are available in any package; you'll... | Nftables rules disappeared after reboot! |
1,651,155,404,000 |
I am trying to build a simple stateful firewall with nftables following the Arch Linux nftables guide. I posted this question on the Arch Linux forum and never received an answer.
After completing the guide and rebooting my machine, systemd failed to load the nftables.service. To troubleshoot the error I ran:
systemct... |
This was a syntax limitation of nftables 0.7 (or a few other versions): it didn't consider ICMP and ICMPv6 directly usable in the dual IPv4/IPv6 table inet without stating explicitly which IP protocol first:
So the rule:
icmp type echo-request ct state new accept
to work both on IPv4 and IPv6 has to be written twice ... | Nftables configuration error: conflicting protocols specified: inet-service v. icmp |
1,651,155,404,000 |
So I have several files which contain CIDR entries (such as 1.1.1.0/24). The task is to add entries from these files to one NFTables set using a bash script. In doing so, I am limited to OpenWRT utilities.
The catch is that there can be many entries in these files and they can exhaust the limit of 4096 characters per ... |
awk can build up a string to execute that can be held below a
particular length; this will doubtless be more efficient than an
xargs that must fork an echo ... | tr pipeline.
#!/usr/bin/env awk
{
len = length()
if (len > limit) {
if (length(outbuf)) {
system("echo " ENVIRON["TARGET_SET"] ou... | How to add CIDRs from files to set in best way? |
1,651,155,404,000 |
I am trying to template stateful nftables configuration file with Ansible.
Ansible uses Jinja for templating and Jinja uses curly braces for variables:
{{ variable }}
Nftables configuration uses curly braces for grouping variables together:
{ 192.168.3.0/24, 192.168.1.0/24 }.
Escaping Jinja2 curly braces looks li... |
If you're using ansible's template module, then you can configure the variable interpolation markers used by Jinja:
Also, you can override jinja2 settings by adding a special header to template file. i.e. #jinja2:variable_start_string:'[%', variable_end_string:'%]', trim_blocks: False which changes the variable inter... | Can I use something else than curly bracket in nftables.conf? |
1,651,155,404,000 |
I am setting up a captive portal on a Raspberry Pi (latest distro CLI) where my web application will change NFTables rules based on who is logged in. I have a LEMP stack set up; with Laravel 8 as the PHP framework.
Nginx/php user is www-data, this user has a sudoers file setup with www-data ALL=(ALL) NOPASSWD:/var/www... |
You can grant specific users the ability to run specific commands with sudo using sudoers files that you place under /etc/sudoers.d/.
The format for this that you could use is:
user host=(who to run as) [Options] Command
Note: You should do all of your editing in visudo.
So if you wanted to give the www-data the priv... | Unable to run scripts as sudo with the www-data user in Debian |
1,651,155,404,000 |
For a netdev filter table's ingress hook I'd like to store the device name in a variable, but I somehow can't figure out the correct syntax.
It works as follows:
table netdev filter {
chain ingress {
type filter hook ingress device ens33 priority -500;
# ...
}
}
... but I would like to use a... |
Alas, this feature was added with this commit made available only since nftables 0.9.7. Your ruleset works as-is when tested with nftables 0.9.8.
src: allow to use variables in flowtable and chain devices
This patch adds support for using variables for devices in the chain
and flowtable definitions, eg.
define if_mai... | How to use variable for device name when declaring a chain to use the (netdev) ingress hook? |
1,651,155,404,000 |
In setting up dynamic blacklists for nftables, per A.B.'s excellent answer, I'm encountering an error when duplicating the blacklist for both ipv4 and ipv6. I perform the following command-line operation (debian nftables) (EDIT: The original question was for a prior version, 0.9.0; during the back-and-forth comment pr... |
try this one
table inet filter {
set blackhole_4 {
type ipv4_addr
flags timeout
}
set blackhole_6 {
type ipv6_addr
flags timeout
}
set greed_4 {
type ipv4_addr
flags dynamic
size 128000
}
set greed_6 {
type ipv6_addr
flags dynamic
size 128000
}
chain input {
... | nftables dynamic blacklisting both IPv4 and IPv6 |
1,651,155,404,000 |
This is my /etc/sysconfig/nftables.conf
#!/usr/sbin/nft -f
flush ruleset
table ip filter {
chain input {
type filter hook input priority filter; policy accept;
ct state established,related counter packets 264 bytes 17996 accept
ct state invalid drop
tcp dport 22 ip saddr 192.168.0.0... |
That's the compatibility table and chains created by the newer version of the ebtables command, used to manipulate bridges, but using the nftables kernel API in ebtables compatibility mode. Something ran an ebtables command somewhere, even if just to verify there's no ebtables rule present, or maybe to auto-load som... | nftables changes on reboot |
1,651,155,404,000 |
I have below nftable rule to add a connection rate meter:
nft add rule ip filter input tcp dport @rate_limit meter syn4-meter \{ ip saddr . tcp dport timeout 5m limit rate 20/minute \} counter accept
It generates the error:
Error: syntax error, unexpected saddr, expecting comma or '}'
add rule ip filter input tcp dp... |
You have two problems:
using a too old version of nftables.
I could reproduce the error Error: syntax error, unexpected saddr, expecting comma or '}' using nftables version 0.7 (as found in Debian 9). Meters (nftables wiki) suggests nftables >= 0.8.1 and kernel >= 4.3.
Upgrade nftables. Eg, on Debian 9, using the str... | nftables meter error: syntax error, unexpected saddr, expecting comma or '}' |
1,651,155,404,000 |
I have a machine that serves both as a router and a server. I have several lxc containers on this machine, and want to expose them to both the LAN and WAN. Following https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-configuring_port_forwarding_using_nftables I was able to... |
Let's look at a part of the Packet flow in Netfilter and General Networking schematic. It was made for iptables but most of it applies for nftables:
It's documented that the nat table is consulted only for packets in conntrack state NEW: packets starting a new flow.
Routed/forwarded traffic arrives from the nat/prer... | nft port forwarding not working on router |
1,651,155,404,000 |
I have a wifi router where the wlan0 interface (radio interface) is bridged with the ethernet interface eth0 (connected to another server acting as DHCP)
/ # brctl show br0
bridge name bridge id STP enabled interfaces
br0 8000.bce67c4d8fb0 no eth0
... |
After some internal help from my org, there are certain rules added elsewhere where marking is happening on packets, which I cannot share on open forum. Based on that the packets were skipping the rate limit rule. I resolved that issue by setting proper marks.
| nftables does not limit ipv6 traffic in rate limit rule in bridge and ip6 family |
1,651,155,404,000 |
I trying to migrate from iptables script to nftables. In this script I want to redirect some outgoing tcp/udp traffic to local proxy excluding some subnets. iptables script works as expected (ip's are changed):
iptables -t nat -N PROXY
iptables -t nat -A PROXY -d 1.1.1.1/32 -j RETURN
iptables -t nat -A PROXY -d 1.0.0... |
Looking at the NFTables configuration you have the line nft add chain nat PROXY { type nat hook prerouting priority -1\; } which includes a prerouting hook which I can not find in your IPTables configuration (iptables -t nat -N PROXY).
Because there is a hook it is not possible to make a jump to it.
This configuration... | nftables error when jumping to `output` chain |
1,651,155,404,000 |
Flowtables is an nftables feature for offloading traffic to a "fast path" that skips the typical forwarding path once a connection is established. Two things need to be configured to set up flowtables. First is the flowtable itself, which is defined as part of a table. Second is a flow offload statement, and this is w... |
There are a few key sentences that I first want to point out from the wiki:
You can select which flows you want to offload through the flow
expression from the forward chain.
Flows are offloaded after the state is created. That means that
usually the first reply packet will create the flowtable entry. A
firewall ru... | How should `flow offload` statements be configured when using flowtables? |
1,651,155,404,000 |
I would like to mirror only a very limited packet traffic destined to a single IP and UDP port to the same IP but a second port. I've locked at https://superuser.com/questions/1593995/iptables-nftables-forward-udp-data-to-multiple-targets but it seems as if nftable's dup statement only allows duplicating to another IP... |
This can be done with nftables and netdev family with an ingress chain and a dup statement. It requires using a mark to avoid an infinite loop. Depending on the exact use case, the duplication can also probably be done on egress (since it's on the loopback interface, the duplicated egress packet will appear back as in... | nftables: duplicate UDP packets for specific destination IP:port to a (second) destination IP:port |
1,651,155,404,000 |
I'd like to take a default drop approach to my firewall rules. I've created some rules for testing purposes:
table bridge vmbrfilter {
chain forward {
type filter hook forward priority -100; policy drop;
ip saddr 192.168.1.10 ip daddr 192.168.1.1 accept;
ip saddr 192.168.1.1 ip daddr 192.16... |
IPv4 over Ethernet relies on ARP to resolve the Ethernet MAC address of the peer in order to send later unicast packets to it.
As you're filtering any ARP request since there's no exception for it, those requests can't succeed and after a typical 3s timeout you'll get the standard "No route to host". There won't be an... | Nftables default drop chain problem |
1,651,155,404,000 |
I have set up nftables on my server and I want to redirect all traffic coming in to certain protected ports (e.g. 80) to be redirected to a higher port which is available without root permissions (e.g. 13080). I want to be able to access only 80 remotely but both ports locally.
This is the setup I came up with:
#!/usr... |
Here's a sample of the Packet flow in Netfilter and General Networking which stays valid for nftables:
There's an important detail written: * "nat" table only consulted for "NEW" connections.
For a locally initiated connection, the first packet of the new connection creates a NEW conntrack state during output (the ou... | nftables destination nat block local access to port |
1,651,155,404,000 |
I am attempting to solve the following problem:
I have a system which I will henceforth refer to as "Local" that hosts a service on port 80 and port 443, and depends on sending outgoing requests on port 25. It also hosts a separate service on port 22.
I have a system which I will call "Global" that has a globally acc... |
Okay so after much consternation I was able to solve my original problem and can therefore post the correct solution here for anyone who might come across this in the future. Application layer configuration is outside the scope of the original question.
Firstly, if you have ufw set up you will need to allow these rul... | How can I configure bidirectional protocol-independent port forwarding? |
1,651,155,404,000 |
I'm trying to atomically replace nftables rules. Nftables's official wiki states that -f is the recommended way to achive this. However, when I run nft -f /path/to/new/rules on Debian Buster, the new rules get added to the current rules instead of replacing them, and I end up with a system enforcing both rule-sets sim... |
The operation done with nft -f /path/to/new/rules is atomic: that means it's either done completely or not done at all (ie: reverted), and will affect all at once the next packet hitting the rules only once committed. It won't end (because of an error) only half-done. So if you don't delete the previous ruleset before... | How do I replace nftables rules atomically? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.