Quote:
Originally posted by Kruncher
No, this is lqorg_user's script, I appended it to my script and I got those errors.
It turns out that gvim put line breaks in the command so it didn't work.
All commands 'work' now, but forwarding still doesn't work.
Here is my revised script (mostly for testing as there is no protection):
#!/bin/sh
#modprobe iptable_nat
#echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P INPUT ACCEPT
#iptables -A INPUT -i ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i ppp0 -j ACCEPT
iptables -A OUTPUT -o ppp0 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A OUTPUT -o eth0 -j ACCEPT
#changed for my protection.
iptables -t nat -A PREROUTING -p tcp -m tcp -d $MYREALIP --dport 80 -j DNAT --to 192.168.0.101:80
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -m state --state NEW -d 192.168.0.101 --dport 80 -j ACCEPT
iptables -A FORWARD -p tcp -m state --state NEW -d 192.168.0.101 --dport 443 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
I run that on my dailup computer. Did I set the rp_filter correctly?
Here is the iptables -L output:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere 192.168.0.101 state NEW tcp dpt:http
ACCEPT tcp -- anywhere 192.168.0.101 state NEW tcp dpt:https
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
What's wrong?
Thank you for your help.
P.S. I set rp_filter to 0 on the internal computer, is that correct?
|
Ok there a several errors with your script, firstly you have the default policy set ACCEPT for all your INPUT,OUTPUT and FORWARD chains. The iptables script reads from top to bottom so it's important where the rules are go. By having the default policy set to ACCEPT this will be the first rule that iptables reads so it will pass the data packet on without reading you other rules further down the script.
Also to use the -m state rule you need to load the ipt_state module, unless you recompiled your kernel to include the module. so yo will need to have modprobe ipt_state in your script at the top. Also line breaks? are you referring to line gaps between the rules? it's ok to have gaps in the script I have many in mine and it works fine for me. Maybe incorporate some of my script to load some of the modules will help, i'll have a go at making a little script out of mine to suit what you have posted and see if that will work for you:
#######################################################################
#!/bin/sh
IPTABLES="/usr/sbin/iptables"
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/all/send_redirects
echo "0" > /proc/sys/net/ipv4/tcp_ecn
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "0" > /proc/sys/net/ipv4/conf/all/secure_redirects
#128 MB of RAM -> 8192 possible entries, 256 MB of RAM --> 16376 possible entries, etc...
echo 8192 > /proc/sys/net/ipv4/ip_conntrack_max
echo 10 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo 15 > /proc/sys/net/ipv4/ipfrag_time
echo 2048 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo "32768 61000" > /proc/sys/net/ipv4/ip_local_port_range
echo "2" > /proc/sys/net/ipv4/tcp_synack_retries
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
## Reduce DoS'ing ability by reducing timeouts
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 2400 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
$IPTABLES -F
$IPTABLES -F -t mangle
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES -X -t mangle
$IPTABLES -X -t nat
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
## Set default policies to DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT ACCEPT
#######################################################################
# lets forward to your web server
$IPTABLES -A INPUT -p tcp -i ppp0 --dport 80 -m state --state NEW -j ACCEPT
$IPTABLES -A PREROUTING -t nat -p tcp -i ppp0 --dport 80 -m state --state NEW -j DNAT --to 192.168.0.101:80
$IPTABLES -A FORWARD -p tcp -o eth0 -d 192.168.0.101 --dport 80 -m state --state NEW -j ACCEPT
# lets forward secure web to your server
$IPTABLES -A INPUT -p tcp -i ppp0 --dport 443 -m state --state NEW -j ACCEPT
$IPTABLES -A PREROUTING -t nat -p tcp -i ppp0 --dport 443 -m state --state NEW -j DNAT --to 192.168.0.101:443
$IPTABLES -A FORWARD -p tcp -o eth0 -d 192.168.0.101 --dport 443 -m state --state NEW -j ACCEPT
#######################################################################
# Genera Rules
#
# INTENET --> FIREWALL/LOCAL NETWORK
#
# allow connections to the router from the internet
$IPTABLES -A INPUT -i ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# allow routing traffic to machines on your local network
$IPTABLES -A FORWARD -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
#######################################################################
# FIREWALL/LOCAL NETWORK --> INTERNET
#
# lets allow all data from the internal network connect to the firewall
$IPTABLES -A INPUT -i eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# lets allow all data from the local network go out to the internet
$IPTABLES -A FORWARD -o ppp0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# lets masqureade all local traffic to have the ip address of your ppp0 device as it goes out to the internet
$IPTABLES -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
#######################################################################
exit 0
# End of Script
#######################################################################
This is a small script with no logging but it should get you out of trouble, let me know if it works