Hey Tweakers,
Ik was dit weekend aan het spelen met netfilter. Hetgeen wat ik wil doen is: sshd binden op localhost, en dan allowed hosts redirecten vanaf mijn eth0 naar localhost. Dit werkt gedeeltelijk: Als ik vanaf mijn lokale systeem connect naar eth0:22 krijg ik een verbinding, als ik dit doe vanaf een remote systeem, krijg ik een timeout
Beats me.....
Anyways, dit is hetgeen wat ik doe:
--[cut here]--------
root:/# cat > /dev/null << EOF
> ip1 == addr van eth0
> ip2 == addr van remote machine
> EOF
root:/# id
uid=0(root) gid=0(root) groups=0(root)
root:/# uname -a
Linux lacrima 2.4.4-work #1 Mon May 14 08:34:52 CEST 2001 i686 unknown
root:/# netstat -an|grep LISTEN
tcp 0 0 0.0.0.0:6000 0.0.0.0: * LISTEN
tcp 0 0 127.0.0.1:22 0.0.0.0: * LISTEN
unix 2 [ ACC ] STREAM LISTENING 1295 /tmp/.X11-unix/X0
root:/# lsmod
Module Size Used by
root:/# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root:/# /sbin/iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root:/# telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# telnet ip1
Trying ip1...
telnet: Unable to connect to remote host: Connection refused
root:/# /sbin/iptables -A INPUT -p tcp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A INPUT -p udp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A FORWARD -p tcp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A FORWARD -p udp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -t nat -A PREROUTING -p tcp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A PREROUTING -p udp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A OUTPUT -p tcp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A OUTPUT -p udp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# iptables -L -n -v
Chain INPUT (policy ACCEPT 173 packets, 24900 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain OUTPUT (policy ACCEPT 18 packets, 1018 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain OUTPUT (policy ACCEPT 18 packets, 1018 bytes)
pkts bytes target prot opt in out source destination
root:/# iptables -L -n -v -t nat
Chain PREROUTING (policy ACCEPT 1494 packets, 210K bytes)
pkts bytes target prot opt in out source destination
4 256 DNAT tcp -- * * 0.0.0.0/0 ip1 tcp dpt:22 to:127.0.0.1:22
0 0 DNAT udp -- * * 0.0.0.0/0 ip1 udp dpt:22 to:127.0.0.1:22
Chain POSTROUTING (policy ACCEPT 93 packets, 5566 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 91 packets, 5446 bytes)
pkts bytes target prot opt in out source destination
2 120 DNAT tcp -- * * 0.0.0.0/0 ip1 tcp dpt:22 to:127.0.0.1:22
0 0 DNAT udp -- * * 0.0.0.0/0 ip1 udp dpt:22 to:127.0.0.1:22
root:/# lsmod
Module Size Used by
iptable_nat 14768 0 (autoclean) (unused)
ip_conntrack 13968 1 (autoclean) [iptable_nat]
iptable_filter 2080 0 (autoclean) (unused)
ip_tables 10368 4 [iptable_nat iptable_filter]
root:/# telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# telnet ip1 22
Trying ip1...
Connected to ip1.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# ssh r3boot@ip2
r3boot@ip2''s password:
Last login: Tue May 1 06:23:52 2001 from x.x.x.x
OpenBSD 2.8 (conf) #4: Mon Mar 5 13:58:44 CET 2001
$ telnet ip1 22
Trying ip1...
telnet: connect to address ip1: Connection timed out
$ Connection to ip2 closed.
root:/#
---[done cut]------
Ik heb de 2.4 packet filter HOWTO en de 2.4 NAT HOWTO gelezen, en "this should do the trick..."
Ik was dit weekend aan het spelen met netfilter. Hetgeen wat ik wil doen is: sshd binden op localhost, en dan allowed hosts redirecten vanaf mijn eth0 naar localhost. Dit werkt gedeeltelijk: Als ik vanaf mijn lokale systeem connect naar eth0:22 krijg ik een verbinding, als ik dit doe vanaf een remote systeem, krijg ik een timeout
Beats me.....
Anyways, dit is hetgeen wat ik doe:
--[cut here]--------
root:/# cat > /dev/null << EOF
> ip1 == addr van eth0
> ip2 == addr van remote machine
> EOF
root:/# id
uid=0(root) gid=0(root) groups=0(root)
root:/# uname -a
Linux lacrima 2.4.4-work #1 Mon May 14 08:34:52 CEST 2001 i686 unknown
root:/# netstat -an|grep LISTEN
tcp 0 0 0.0.0.0:6000 0.0.0.0: * LISTEN
tcp 0 0 127.0.0.1:22 0.0.0.0: * LISTEN
unix 2 [ ACC ] STREAM LISTENING 1295 /tmp/.X11-unix/X0
root:/# lsmod
Module Size Used by
root:/# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root:/# /sbin/iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root:/# telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# telnet ip1
Trying ip1...
telnet: Unable to connect to remote host: Connection refused
root:/# /sbin/iptables -A INPUT -p tcp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A INPUT -p udp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A FORWARD -p tcp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -A FORWARD -p udp -d 127.0.0.1 --dport 22 -j ACCEPT
root:/# /sbin/iptables -t nat -A PREROUTING -p tcp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A PREROUTING -p udp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A OUTPUT -p tcp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# /sbin/iptables -t nat -A OUTPUT -p udp -d ip1 --dport 22 -j DNAT --to 127.0.0.1:22
root:/# iptables -L -n -v
Chain INPUT (policy ACCEPT 173 packets, 24900 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain OUTPUT (policy ACCEPT 18 packets, 1018 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 127.0.0.1 udp dpt:22
Chain OUTPUT (policy ACCEPT 18 packets, 1018 bytes)
pkts bytes target prot opt in out source destination
root:/# iptables -L -n -v -t nat
Chain PREROUTING (policy ACCEPT 1494 packets, 210K bytes)
pkts bytes target prot opt in out source destination
4 256 DNAT tcp -- * * 0.0.0.0/0 ip1 tcp dpt:22 to:127.0.0.1:22
0 0 DNAT udp -- * * 0.0.0.0/0 ip1 udp dpt:22 to:127.0.0.1:22
Chain POSTROUTING (policy ACCEPT 93 packets, 5566 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 91 packets, 5446 bytes)
pkts bytes target prot opt in out source destination
2 120 DNAT tcp -- * * 0.0.0.0/0 ip1 tcp dpt:22 to:127.0.0.1:22
0 0 DNAT udp -- * * 0.0.0.0/0 ip1 udp dpt:22 to:127.0.0.1:22
root:/# lsmod
Module Size Used by
iptable_nat 14768 0 (autoclean) (unused)
ip_conntrack 13968 1 (autoclean) [iptable_nat]
iptable_filter 2080 0 (autoclean) (unused)
ip_tables 10368 4 [iptable_nat iptable_filter]
root:/# telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# telnet ip1 22
Trying ip1...
Connected to ip1.
Escape character is ''^]''.
SSH-1.99-OpenSSH_2.9p1
quit
Protocol mismatch.
Connection closed by foreign host.
root:/# ssh r3boot@ip2
r3boot@ip2''s password:
Last login: Tue May 1 06:23:52 2001 from x.x.x.x
OpenBSD 2.8 (conf) #4: Mon Mar 5 13:58:44 CET 2001
$ telnet ip1 22
Trying ip1...
telnet: connect to address ip1: Connection timed out
$ Connection to ip2 closed.
root:/#
---[done cut]------
Ik heb de 2.4 packet filter HOWTO en de 2.4 NAT HOWTO gelezen, en "this should do the trick..."