Tag Archives: iptables

Raspberry Pi 3 error IPTables | Raspberry pi error – iptables v1.4.21: can’t initialize iptables table `nat’: Table does not exist (do you need to insmod?)

Was building a RPi3 machine and got the following error after an update.

Turns out nothing to worry about, just reboot the Pi.

How to setup hostapd and dnsmasq on a Raspberry Pi 1 | setup wifi access point on a raspberry pi 1 with hostapd and dnsmasq

I decided to setup Hostapd and DNSMasq on my Raspberry Pi 1 as part of a bigger project. This makes an awesome project to setup a router. See below.

This will install the applications.

Lets block DHCPd by editing

Add this line to the bottom.

Lets setup Hostapd

Enable the hostapd.conf config.

Ensure the following live is present.

Paste the following into the configuration file, ensure you change the sections which relate to you. Pay attention to ssid and wpa password.

Lets setup DNSMasq.

Put the following into the config file.

Now we enable IP forwarding on a system level

Uncomment the following line

Setup the IPtables NAT rules

Lets save the IPTables rules permanently.

Lets ensure they run on reboot

and ensure the following is present before the “exit 0”.

Reboot and your done!

 

 

 

Blocking All IPs Outside Your Country | iptables linux centos ubuntu blocking coutries

I want to block all traffic that does not originate from my country (Australia)

Best way to do this is using IPTables, Australia alone has around 4500 IP ranges to block.

What I did was download the ranges from Maxmind in CSV format, link

So we need to covert the format of the CSV file to a format IPTABLES can import, I wrote the following script.

Change the country name to match your country,  it will work.

This will produce the whitelist required to block all other IPs, you will also need to append a deny all at the end, so this.

IPTables blocking outbound port to specific host. | centos redhat linux iptables outbound port block drop dport ip

I needed to write a iptables rule to block outbound traffic to a specific host here.

Now I need to write a similar rule which will not block the entire host but just a single port to a host.

The rule is very simlar to the previously state but with the port flag, see below.

 

IPTABLES blocking traffic outbound to a specific IP | iptables block ip hosts outbound

I was in a situation today where an application was talking to hosts it shouldn’t have. A quick way to stop this from happening was with iptables. Make sure you ping the host first before the rule and after to ensure it has taken affect.

The rule to block a specific IP is

To check the rule is in,

To remove the rule, the ‘1’ means the first line in the table, in this case this was the only outbound rule.