Skip to contentSkip to conversation

udp port forwarding from internal network to internet

DISCUSSION Kevin Van Workum 2 participants 6 messages Jan 27, 2005

lore
Share & tools
lore
#0 lore raw

I'm new to netfilter and iptables and need to get something up and running fast. I don't have time to read up and learn the details right now.

I have one server machine connected to the internet via a cable modem with a static IP and a small internal network (10.0.0.0). All machines have the 2.4 kernel. I have a user who needs to run an application on a few machines on the internal network. This application needs to connect to a server located on the internet via a udp port. How can I use iptables (or a proxy or whatever) to do this?

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#1 lore raw
Quoted 4 lines · Kevin Van Workum

I'm new to netfilter and iptables and need to get something up and running fast. I don't have time to read up and learn the details right now.

Quoted 8 lines

I have one server machine connected to the internet via a cable modem with a static IP and a small internal network (10.0.0.0). All machines have the 2.4 kernel. I have a user who needs to run an application on a few machines on the internal network. This application needs to connect to a server located on the internet via a udp port. How can I use iptables (or a proxy or whatever) to do this?

  # adjust these to suit
  INT_IF=eth1
  EXT_IF=eth0
  EXT_IP=`ip -4 -o addr sh $EXT_IF | awk '{print $4}' | cut -d"/" -f1`
  SRV_IP=1.2.3.4
  SRV_PORT=1111
  iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

  iptables -A FORWARD -i $INT_IF -o $EXT_IF -p udp -d $SRV_IP \
    --dport $SRV_PORT -j ACCEPT

  iptables -t nat -A POSTROUTING -o $EXT_IF -j SNAT --to-source $EXT_IP

-j

--
"'Wet Cement' - is there any sweeter sign? Maybe 'High Voltage.'"
--The Simpsons

#2 lore raw
Quoted 25 lines · --- Jason Opperisano
Quoted 1 line

I have one server machine connected to the

internet

Quoted 2 lines

via a cable modem with a static IP and a small internal network (10.0.0.0). All machines have the

2.4

Quoted 1 line

kernel. I have a user who needs to run an

application

Quoted 2 lines

on a few machines on the internal network. This
application needs to connect to a server located

on

Quoted 1 line

the internet via a udp port. How can I use

iptables

Quoted 1 line

(or a proxy or whatever) to do this?

  # adjust these to suit
  INT_IF=eth1
  EXT_IF=eth0
  EXT_IP=`ip -4 -o addr sh $EXT_IF | awk '{print
$4}' | cut -d"/" -f1`
  SRV_IP=1.2.3.4
  SRV_PORT=1111

iptables -A FORWARD -m state --state
ESTABLISHED,RELATED -j ACCEPT

Quoted 6 lines

iptables -A FORWARD -i $INT_IF -o $EXT_IF -p udp
-d $SRV_IP \
--dport $SRV_PORT -j ACCEPT

iptables -t nat -A POSTROUTING -o $EXT_IF -j SNAT
--to-source $EXT_IP

Thanks. Just so I understand what I'm doing here. SVR_IP is the IP of the server on the internet that my app on my internal network is conntacting? What is the effect of these rules?
Can you explain in english what these rules mean? What IP does my app connect to, the internal IP of my server with the internet connection?

__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

#3 lore raw
Quoted 2 lines · Kevin Van Workum
Quoted 2 lines
  # adjust these to suit
  INT_IF=eth1

is the internal interface of the firewall machine

Quoted 1 line
Quoted 1 line

EXT_IF=eth0

is the external interface of the firewall machine

Quoted 2 lines
Quoted 2 lines

EXT_IP=`ip -4 -o addr sh $EXT_IF | awk '{print
$4}' | cut -d"/" -f1`

is the external ip address of the firewall machine

Quoted 1 line
Quoted 1 line

SRV_IP=1.2.3.4

is the IP address of the server on the internet you're trying to connect to

Quoted 1 line
Quoted 1 line

SRV_PORT=1111

is the UDP port you're trying to connect to on the server on the internet

Quoted 2 lines
Quoted 2 lines

iptables -A FORWARD -m state --state
ESTABLISHED,RELATED -j ACCEPT

allows the replies to established connections and related connections and error messages through the FORWARD chain of the firewall

Quoted 3 lines
Quoted 3 lines

iptables -A FORWARD -i $INT_IF -o $EXT_IF -p udp
-d $SRV_IP \
--dport $SRV_PORT -j ACCEPT

allows packets arriving inbound on the internal interface destined for the udp port on the server on the internet to be forwarded through the firewall

Quoted 2 lines
Quoted 2 lines

iptables -t nat -A POSTROUTING -o $EXT_IF -j SNAT
--to-source $EXT_IP

translates the source IP of packets exiting the firewall to the external IP address of the firewall.

Quoted 3 lines

Thanks. Just so I understand what I'm doing here. SVR_IP is the IP of the server on the internet that my app on my internal network is conntacting?

yup.

Quoted 4 lines

What is the effect of these rules?
Can you explain in english what these rules mean? What IP does my app connect to, the internal IP of my server with the internet connection?

nope--the IP of the server on the internet.

-j

--
"Homer no function beer well without."
--The Simpsons

#4 lore raw
Quoted 5 lines
Quoted 1 line

What IP does my app connect to, the internal IP of

my

Quoted 1 line

server with the internet connection?

nope--the IP of the server on the internet.

How does the machine on the internal network know to go through my firewall server to make the connection? Is there any configuration required on the internal machine running the app?

__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

#5 lore raw
Quoted 10 lines · Kevin Van Workum
Quoted 5 lines
Quoted 1 line

What IP does my app connect to, the internal IP of

my

Quoted 1 line

server with the internet connection?

nope--the IP of the server on the internet.

How does the machine on the internal network know to go through my firewall server to make the connection? Is there any configuration required on the internal machine running the app?

normally--the default gateway of the internal machine would be the internal IP of the firewall. if this is not the case--you will need to make a change to your internal routing to make sure these packets get routed to the firewall.

-j

--
"Lisa, if you don't like your job you don't strike. You just go in
there every day and do it really half-assed. That's the American way."
--The Simpsons