forwarding werkt niet

Pagina: 1
Acties:

  • B2
  • Registratie: April 2000
  • Laatst online: 23:26

B2

wa' seggie?

Topicstarter
Ik gebruik de volgende regel in me script voor het forwarden van extern verkeer naar me interne webserver
code:
1
2
3
4
# Testbak doorsturen
    # ------------------
    iptables -A INPUT -p tcp -s $UNIVERSE -d 10.0.0.19 --dport 80 -j ACCEPT
    iptables -A PREROUTING -t nat -p tcp -d ip --dport 8080 -j DNAT --to 10.0.0.19:80

Maar het werkt niet.
Volgens mij moet het toch wel werken zo?

Ik probeer dus in me browser te connecten aan ip:8080 om naar de interne bak op poort 80 te gaan.

[ Voor 3% gewijzigd door B2 op 22-03-2010 21:08 ]


  • moto-moi
  • Registratie: Juli 2001
  • Laatst online: 09-06-2011

moto-moi

Ja, ik haat jou ook :w

Heb je ook IP-forwarding aangezet ?
oftewel, wat zegt
code:
1
cat /proc/sys/net/ipv4/ip_forward

? Die moet als het goed is, een simpel eentje(1) aangeven..
anders ff
code:
1
echo 1 > /proc/sys/net/ipv4/ip_forward

God, root, what is difference? | Talga Vassternich | IBM zuigt


  • B2
  • Registratie: April 2000
  • Laatst online: 23:26

B2

wa' seggie?

Topicstarter
Ja tuurlijk, het Masquerade ook al het verkeer naar interne net.

  • asusk7m550
  • Registratie: Oktober 2000
  • Laatst online: 12-08 11:49

asusk7m550

Athlon 550@500

Die eerde regel van je:
code:
1
iptables -A input -p tcp -s $UNIVERSE -d 10.0.0.19 --dport 80 -j ACCEPT

Wat moet ik me daarbij voorstellen?

Er is niemand in het UNIVERSE die zomaar binnenkomt bij je, en gelijk naar ip 10.0.0.19 gaat vragen.
Je vergeet dus een stapje.
Als je invult
code:
1
2
3
iptables -A input -p tcp -s $UNIVERSE -d 212.187.19.169 --dport 8080 -j ACCEPT
iptables -A PREROUTING -t nat -p tcp -d 212.187.19.169 --dport 8080 -j DNAT --to 10.0.0.19:80
iptables -A output -p tcp -s 10.0.0.x -d 10.0.0.19 --dport 80 -j ACCEPT

denk ik dat ie meer doet. Ik ben niet thuis in iptables, wel in ipchains.
Maar je ACCEPT het verkeer van buiten naar een internet netwerk adres. En dan kan niet.

Je moet dus eerst het verkeer accepteren van buiten naar je buiten adres, dat verkeer dan gaan 'NATTEN' en als het moet ook het verkeer van je interne adres naar je andere machine accepteren.

It takes only a minute to get a crush on someone, an hour to like someone, and a day to love someone, but it takes a lifetime to forget someone.


  • B2
  • Registratie: April 2000
  • Laatst online: 23:26

B2

wa' seggie?

Topicstarter
Nee werkt niet, minder :(
Alleen de derde regel die je geeft is niet noodzakelijk bij mij, omdat ik al een regel heb staan dat alle verkeer in het interne net zo-ie-zo mag.

Voor de zekerheid me script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
IPADDR=`ifconfig eth0 | fgrep -i inet | cut -d : -f 2 | cut -d \  -f 1`
EXTERNAL_INTERFACE="eth0"                # Internet connected interface
LOOPBACK_INTERFACE="lo"              # Your local naming convention
LOCAL_INTERFACE_1="eth1"                # Your Internal LAN interface
LOCAL_IP=`ifconfig eth1 | fgrep -i inet | cut -d : -f 2 | cut -d \  -f 1`
INTRANET="10.0.0.0/8"                  # Your Private IP Addr Range
PRIMARY_NAMESERVER="212.142.28.66"          # Your Primary Name Server
SECONDARY_NAMESERVER="212.142.28.130"         # Your Secondary Name Server
#SYSLOG_SERVER="***.**.**.*"              # Your Syslog Internal Server
UNIVERSE="0.0.0.0/0"

LOOPBACK="127.0.0.0/8"                # Reserved loopback address range
CLASS_A="10.0.0.0/8"                    # Class A private networks
CLASS_B="172.16.0.0/12"              # Class B private networks
CLASS_C="192.168.0.0/16"                # Class C private networks
CLASS_D_MULTICAST="224.0.0.0/4"          # Class D multicast addr
CLASS_E_RESERVED_NET="240.0.0.0/5"        # Class E reserved addr
BROADCAST_SRC="0.0.0.0"              # Broadcast source addr
BROADCAST_DEST="255.255.255.255"            # Broadcast destination addr
PRIVPORTS="0:1023"                  # Privileged port range
UNPRIVPORTS="1024:65535"                     # Unprivileged port range

# ----------------------------------------------------------------------------

# The SSH client starts at 1023 and works down to 513 for each
# additional simultaneous connection originating from a privileged port.
# Clients can optionally be configured to use only unprivileged ports.
SSH_LOCAL_PORTS="1022:65535"              # Port range for local clients
SSH_REMOTE_PORTS="513:65535"              # Port range for remote clients

# traceroute usually uses -S 32769:65535 -D 33434:33523
TRACEROUTE_SRC_PORTS="32769:65535"
TRACEROUTE_DEST_PORTS="33434:33523"

# ----------------------------------------------------------------------------

# Default policy is DENY
# Explicitly accept desired INCOMING & OUTGOING connections

    # Remove all existing rules belonging to this filter
    iptables -F
    iptables -F -t nat

    # Remove any existing user-defined chains.
    iptables -X

    # Set the default policy of the filter to deny.
    iptables -P INPUT   DROP
    iptables -P OUTPUT  DROP
    iptables -P FORWARD DROP

# ----------------------------------------------------------------------------

# LOOPBACK
# --------

    # Unlimited traffic on the loopback interface.

    iptables -A INPUT  -i $LOOPBACK_INTERFACE  -j ACCEPT
    iptables -A OUTPUT -o $LOOPBACK_INTERFACE  -j ACCEPT

# ----------------------------------------------------------------------------

# Unlimited traffic within the local network.

    # All internal machines have access to the firewall machine.

    iptables -A INPUT  -i $LOCAL_INTERFACE_1 -s $INTRANET -j ACCEPT
    iptables -A OUTPUT -o $LOCAL_INTERFACE_1 -d $INTRANET -j ACCEPT

# ----------------------------------------------------------------------------

# STATEFUL PART!
# --------------
    # Kill malformed XMAS packets
    iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
    iptables -A FORWARD -p tcp --tcp-flags ALL ALL -j DROP

    # Kill malformed NULL packets
    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
    iptables -A FORWARD -p tcp --tcp-flags ALL NONE -j DROP

    # Block faked, or "spoofed," packets from getting through the firewall.
    #iptables -A FORWARD -i $LOCAL_INTERFACE_1 -s ! $INTRANET -j DROP

    # Allow all internal packets out of our network.
    iptables -A FORWARD -m state --state NEW,RELATED,ESTABLISHED -i $LOCAL_INTERFACE_1 \
         -s $INTRANET -j ACCEPT

    # Allow the associated packets with those connections back in.
    iptables -A FORWARD -m state --state ESTABLISHED,RELATED \
         -i $EXTERNAL_INTERFACE -s ! $INTRANET -j ACCEPT

    # All internal traffic is masqueraded externally.
    iptables -A POSTROUTING -t nat -o $EXTERNAL_INTERFACE -j MASQUERADE

# Blocks any forwards that come from Internet connection. Uncomment only for
# users with modem device like "ppp0".

#    iptables -A FORWARD -i $EXTERNAL_INTERFACE -m state \
#    --state NEW,INVALID -j REJECT

# ----------------------------------------------------------------------------

# Network Ghouls

    # Deny access to jerks
    # --------------------
    # /etc/rc.d/rc.firewall.blocked contains a list of
    # iptables -A INPUT -i $EXTERNAL_INTERFACE -s address -j DROP
    # rules to block from any access.

    # Refuse any connection from problem sites
    if [ -f /etc/rc.d/rc.firewall.blocked ]; then
    deny_file="/etc/rc.d/rc.firewall.blocked"
    temp_file="/tmp/temp.ip.addresses"
    cat $deny_file | sed -n -e "s/^[ ]*\([0-9.]*\).*$/\1/p" \
    | awk ' $1 ' > $temp_file
    while read ip_addy
    do
    case $ip_addy in
      *) iptables -A INPUT -i $EXTERNAL_INTERFACE -s $ip_addy -j DROP
         iptables -A INPUT -i $EXTERNAL_INTERFACE -d $ip_addy -j DROP
         iptables -A OUTPUT -o $EXTERNAL_INTERFACE -s $ip_addy -j REJECT
         iptables -A OUTPUT -o $EXTERNAL_INTERFACE -d $ip_addy -j REJECT
      ;;
     esac
    done < $temp_file
    rm -f $temp_file > /dev/null 2>&1
    unset temp_file
    unset deny_file
    fi

# ----------------------------------------------------------------------------

# SPOOFING & BAD ADDRESSES
# Refuse spoofed packets.
# Ignore blatantly illegal source addresses.
# Protect yourself from sending to bad addresses.

    # Refuse incoming packets pretending to be from the external address.
    #iptables -A INPUT   -s $IPADDR -j DROP

    # Refuse incoming packets claiming to be from a Class A, B or C private network
    iptables -A INPUT   -s $CLASS_A -j DROP
    iptables -A INPUT   -s $CLASS_B -j DROP
    iptables -A INPUT   -s $CLASS_C -j DROP    # Refuse broadcast address SOURCE packets
    #iptables -A INPUT   -s $BROADCAST_DEST -j DROP
    #iptables -A INPUT   -d $BROADCAST_SRC -j DROP

    # Refuse Class D multicast addresses
    # Multicast is illegal as a source address.
    # Multicast uses UDP.
    iptables -A INPUT   -s $CLASS_D_MULTICAST -j DROP

    # Refuse Class E reserved IP  addresses
    iptables -A INPUT   -s $CLASS_E_RESERVED_NET -j DROP

    # Refuse special addresses defined as reserved by the IANA.
    # Note:  The remaining reserved addresses are not included
    # filtering them causes problems as reserved blocks are
    # being allocated more often now. The following are based on
    # reservations as listed by IANA as of 2001/01/04. Please regularly
    # check at http://www.iana.org/ for the latest status.

    # Note:  this list includes the loopback, multicast, & reserved addresses.

    # 0.*.*.*            - Can't be blocked for DHCP users.
    # 127.*.*.*          - LoopBack
    # 169.254.*.*          - Link Local Networks
    # 192.0.2.*          - TEST-NET
    # 224-255.*.*.*      - Classes D & E, plus unallocated.

    #iptables -A INPUT   -s 0.0.0.0/8 -j DROP
    iptables -A INPUT   -s 127.0.0.0/8 -j DROP
    iptables -A INPUT   -s 169.254.0.0/16 -j DROP
    iptables -A INPUT   -s 192.0.2.0/24 -j DROP
    iptables -A INPUT   -s 224.0.0.0/3 -j DROP

# ----------------------------------------------------------------------------

    # UDP TRACEROUTE
    # --------------

    # traceroute usually uses -S 32769:65535 -D 33434:33523

    iptables -A INPUT  -i $EXTERNAL_INTERFACE -p udp  \
         --source-port $TRACEROUTE_SRC_PORTS \
         -d $IPADDR --destination-port $TRACEROUTE_DEST_PORTS -j DROP

    iptables -A OUTPUT -o $EXTERNAL_INTERFACE -p udp  \
         -s $IPADDR --source-port $TRACEROUTE_SRC_PORTS \
         --destination-port $TRACEROUTE_DEST_PORTS -j ACCEPT

# ----------------------------------------------------------------------------

    # Testbak doorsturen
    # ------------------
    iptables -A input -p tcp -s $UNIVERSE -d 212.187.19.169 --dport 8080 -j ACCEPT
    iptables -A PREROUTING -t nat -p tcp -d 212.187.19.169 --dport 8080 -j DNAT --to 10.0.0.19:80
    #iptables -A output -p tcp -s 10.0.0.0/8 -d 10.0.0.19 --dport 80 -j ACCEPT

Ik hoop dat je er wat mee kunt.

  • B2
  • Registratie: April 2000
  • Laatst online: 23:26

B2

wa' seggie?

Topicstarter
Hmz, met die drie regels zie ik op de interne bak wel via tcpdump dat er connectie wordt gemaakt.
Alleen er wordt dus niks teruggezonden of dat komt niet aan.
code:
1
2
3
iptables -A input -p tcp -s $UNIVERSE -d 212.187.19.169 --dport 8080 -j ACCEPT
    iptables -A PREROUTING -t nat -p tcp -d 212.187.19.169 --dport 8080 -j DNAT --to 10.0.0.19:80
    iptables -A output -p tcp -s 10.0.0.0/8 -d 10.0.0.19 --dport 80 -j ACCEPT

  • imdos
  • Registratie: Maart 2000
  • Laatst online: 05-08 12:09

imdos

I use FreeNAS and Ubuntu

je probeert toch wel daadwerkelijk te connecten van buitenaf? en niet van binnenaf .. En zo te zien heb je dit script mooi geknipt & geplakt ;) :+

pvoutput. Waarom makkelijk doen, als het ook moeilijk kan! Every solution has a new problem


  • B2
  • Registratie: April 2000
  • Laatst online: 23:26

B2

wa' seggie?

Topicstarter
Op woensdag 24 oktober 2001 11:39 schreef imdos het volgende:
je probeert toch wel daadwerkelijk te connecten van buitenaf? en niet van binnenaf .. En zo te zien heb je dit script mooi geknipt & geplakt ;) :+
Ja heb het ook door iemand anders laten proberen, en dat knippen plakken, het script komt van OpenNA, met wat eigen aanpassingen verderop.

Toch raar want hiervoor draaide OpenBSD op de bak, en daar werkte het redirecten wel mee...

Verwijderd

Op dinsdag 23 oktober 2001 21:38 schreef postduif het volgende:
Ik gebruik de volgende regel in me script voor het forwarden van extern verkeer naar me interne webserver
code:
1
2
3
4
# Testbak doorsturen
    # ------------------
    iptables -A INPUT -p tcp -s $UNIVERSE -d 10.0.0.19 --dport 80 -j ACCEPT
    iptables -A PREROUTING -t nat -p tcp -d 212.187.19.169 --dport 8080 -j DNAT --to 10.0.0.19:80

Maar het werkt niet.
Volgens mij moet het toch wel werken zo?

Ik probeer dus in me browser te connecten aan 212.187.19.169:8080 om naar de interne bak op poort 80 te gaan.
ALs je met pre-routing de destination van je packetjes gaat wijzigen naar een intern adres komt dit NIET op de INPUT chain maar wel op de FORWARD chain
Op de INPUT chain komt enkel verkeer bestemd voor die PC
En op de OUTPUT chain komt enkel verkeer gegenereert door die PC.

Dit is een van de verschillen tussen ipchains en iptables.
Pagina: 1