Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Hello I have this routing script that I'm using which runs when all the network interfaces are up:

#!/bin/sh

PATH=/usr/sbin:/sbin:/bin:/usr/bin

#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT


# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

# Don't forward from the outside to the inside.
iptables -A FORWARD -i wlan0 -o wlan0 -j REJECT

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward

wlan0 is my wifi connection to my android phones wifi tether, ip range is 192.168.43.0/24 eth0 is my LAN connection, ip range: 10.1.1.0/24

I've noticed when the script gets to this line:

iptables -A INPUT -m state --state NEW -i ! wlan0 -j ACCEPT

It comes up with the error:

Bad argument `wlan0'
Try `iptables -h' or 'iptables --help' for more information.

Being a noob with iptables, I'm not too sure what is wrong.

Would anyone be able to enlighten me on this?

share|improve this question
1  
You've swapped the -i and ! parameters. See the manual page of iptables (or iptables-extensions for modern versions). –  Lekensteyn Jan 20 at 22:39
    
wow... it was that easy, I feel stupid. Also how would I forward that port from the outside into my lan? –  FortuneCookie101 Jan 20 at 22:48

1 Answer 1

up vote 0 down vote accepted

For future reference or for anyone looking at this page here is the finished script:

#!/bin/sh

PATH=/usr/sbin:/sbin:/bin:/usr/bin

#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW ! -i wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

# Don't forward from the outside to the inside.
iptables -A FORWARD -i wlan0 -o wlan0 -j REJECT

#Port Forward Unifed remote
iptables -A INPUT -p tcp --dport 9512 -j ACCEPT -i wlan0
iptables -t nat -A PREROUTING -p tcp --dport 9512 -j DNAT --to-destination 10.1.1.12:9512
iptables -t nat -A POSTROUTING -d 10.1.1.12 -p tcp --dport 9512 -j SNAT --to-source 10.1.1.1

# Drop outside traffic except ssh
iptables -A INPUT -p tcp --dport ssh -j ACCEPT -i wlan0
iptables -A INPUT -j DROP -p tcp -i wlan0

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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