25

How do I fix the iptables: command not found problem that happened to Debian 7.6?

batman@gotham:~$ uname -a Linux gotham 3.14-0.bpo.2-amd64 #1 SMP Debian 3.14.13-2~bpo70+1 (2014-07-31) x86_64 GNU/Linux batman@gotham:~$ iptables -L bash: iptables: command not found batman@gotham:~$ sudo apt-get install iptables [sudo] password for batman: Reading package lists... Done Building dependency tree Reading state information... Done iptables is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. batman@gotham:~$ 

I googled extensively and most of the answers were for CentOS and Fedora that dated back to 2005 and 2009.

3
  • What's the output of echo $PATH? Commented Aug 16, 2014 at 11:44
  • 1
    iptables should be in your PATH so it is the sudo you are missing. Commented Aug 16, 2014 at 12:19
  • What happenned to me is that iptables is not installed by default. And sudo apt install iptables works. OP has iptables installed obviously. Commented Jul 31, 2022 at 9:30

5 Answers 5

22

The iptables command can pretty much only be usefully run as root, not as another user. So it is not in the default command search path for users other than root.

To run iptables, run it as root, with either of these commands:

su 'iptables --some-option …' sudo iptables --some-option … 

The executable is located in /sbin, which is in the default command search path for root.

10

It's because iptables is not listed in your PATH variable. I think it should work with the sudo command. Try:

sudo iptables -L 

If that too doesn't work then you should checkout where the iptables binary is and then add it to the PATH variable.

In most cases it should be in /sbin/. Still, just verify in Debian7. If it is in /sbin/ then you can open .bashrc file and provide this at the end:

PATH=/sbin/:$PATH 
8
  • you should checkout where the iptables binary is What command should I type to locate the iptables binary? Commented Aug 16, 2014 at 12:19
  • then you can open .bashrc file and Where is the location of .bashrc file? Commented Aug 16, 2014 at 12:20
  • 1
    did you check with sudo? Try dpkg -L iptables to list out the files. Commented Aug 16, 2014 at 12:20
  • What about .bashrc file? Where's it located? Commented Aug 16, 2014 at 13:07
  • 2
    Well these are the basics. Ok it is in your home directory. Trying opening from your terminal. vim ~/.bashrc Commented Aug 16, 2014 at 13:08
7

This is probably not the answer to your question. But there are those who are facing the same problem and have not installed iptable

you may try installing the iptables package as shown below as per your choice of distribution.

Distribution Command
Debian apt-get install iptables
Ubuntu apt-get install iptables
Alpine apk add iptables
Arch Linux pacman -S iptables
Kali Linux apt-get install iptables
CentOS yum install iptables
Fedora dnf install iptables
Raspbian apt-get install iptables
2
  • The answer is not really following the scenario explained in the question Commented Nov 2, 2022 at 11:00
  • 2
    This page comes up in Google for other scenarios as well. So it is not bad that this answer is included among the answers, it may be useful for someone. Commented Nov 2, 2022 at 13:09
1

dpkg -L iptables will show where the files are installed from the package iptables.

dpkg -L iptables | grep iptables$ 

You can check the location of iptables binary file. For me on Ubuntu it is in /sbin/iptables.

So run with /sbin/iptables -L and check.

1

In some distributions, iptables is not installed, and it's also considered old.

In these distributions, you probably have the nft command instead. If yes, you may want to document yourself about nftables instead:

https://wiki.debian.org/nftables

This may be a useful tutorial:

https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.