Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-04-2004, 10:45 AM   #1 (permalink)
Poo-tee-weet?
 
JStrider's Avatar
 
Location: The Woodlands, TX
packet forwarding with linux

ok so ive got a system running redhat 9 its got 2 nics and i want to be able to have it forward packets to my normal windows box, but i also want to use the linux box for my dc hub and a webhost... I have a friend who can help me with the webhost and the dchub... but he doesnt know how to do the packet forwarding...

any help would be appreciated...

and i dont want the linux box to act like a firewall
__________________
-=JStrider=-

~Clatto Verata Nicto
JStrider is offline  
Old 02-04-2004, 11:15 AM   #2 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Well packet forwarding in itself is a minimum firewall, as it usually shields the identity and type of machine(s) behind it.

My setup sounds like yours (only I don't use dcc or a httpserver).
You should take a look at iptables. It is capable of what you ask and a lot more.
I believe most distro's install it automatically.

Iptables needs to be compiled into the kernel, so you might have some work there.
Next, it needs a rule set which is probably very simple for your setup

As an idea my firewall script (run at startup) is somewhat like this:
Code:
#!/bin/sh

  # Turn on IP forwarding in the kernel
  echo "1" > /proc/sys/net/ipv4/ip_forward
  echo "************ STARTING ipTABLES config ***************"

#create variables to contain network devices
#private LAN:
  PRIVATE_IF=eth0
#Public Internet:
  PUBLIC_IF=ppp0
#LAN address space:
  PRIVATE_NET=10.0.0.0/16


#Flush and re-fill ip-tables ruleset:

  /sbin/iptables -F
  /sbin/iptables -F -t nat
  /sbin/iptables -P INPUT ACCEPT
  /sbin/iptables -P FORWARD DROP
  /sbin/iptables -P OUTPUT ACCEPT

#some bastard I don't like was on this IP:
  /sbin/iptables --append PREROUTING -t nat -s 217.155.0.0/16 -j DROP

#enable LAN-to-Internet traffic (masqueraded)
  /sbin/iptables -t filter -A FORWARD -i $PRIVATE_IF -o $PUBLIC_IF -s $PRIVATE_NET -d ! $PRIVATE_NET -j ACCEPT

  /sbin/iptables -t filter -A FORWARD -i $PUBLIC_IF -o $PRIVATE_IF -s ! $PRIVATE_NET -d $PRIVATE_NET -j ACCEPT

  /sbin/iptables -t nat -A POSTROUTING -o $PUBLIC_IF -d ! $PRIVATE_NET -s $PRIVATE_NET -j MASQUERADE

  echo "iptables enabled"


####### Outside-to-LAN access:  ##########

#Dungeon Siege

/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port 6073 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:6073
/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port 2302 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:2302
/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port 2300 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:2300
/sbin/iptables -t nat -A PREROUTING -p udp --destination-port 6073 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:6073
/sbin/iptables -t nat -A PREROUTING -p udp --destination-port 2302 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:2302
/sbin/iptables -t nat -A PREROUTING -p udp --destination-port 2300 -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3:2300
The first section above enables masquerading, allowing internet access from within your complete LAN, masked as traffic coming from your gateway only.

The second section (I use mainly for games) allows outsiders to access your internal LAN by addressing the gateway on certain ports.

I hope this helps.

Disclaimer: The above rules don't originate from any howto's I've seen before and may or may not be completely 'right'. They do work fine however in my current setup.
2nd note: If you want all traffice except dc and http forwarded to your internal machine, you would probably replace the second section by more general rules. (hint: port-ranges are allowed if setup right in newer kernels)
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)

Last edited by Silvy; 02-05-2004 at 01:51 AM..
Silvy is offline  
Old 02-04-2004, 03:51 PM   #3 (permalink)
Poo-tee-weet?
 
JStrider's Avatar
 
Location: The Woodlands, TX
so if i use that how can i change it to let everything through?...

and where would i put that... and set it up to run at startup... im very n00b when it comes to linux so im gonna need like step by step instructions...
__________________
-=JStrider=-

~Clatto Verata Nicto
JStrider is offline  
Old 02-05-2004, 01:48 AM   #4 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
First of all:
- I'm assuming you got RedHat successfully connected to the internet and your back-end PC, if not, set that up first. (post a new thread if you need help with that.)
- The first step below can mess up your system pretty good, so be careful!
- READ! When using my example script verify that you know what each line does, if unsure: ask! When compiling the kernel, read the associated help files! I may forget a step or make a mistake. Convince yourself that you know what is going to happen before you do it.
- I am also assuming you're working from the command line and not within X. Red Hat has some GUI tools for firewalling/forwarding but I've never used them so I can't help you with that. I think they are pretty well documented however so you could give them a try. (if you do: disregard the rest of this post as it assumes you do all by hand.)
- Some rules in the above post got commented, I will edit to remove the #'s.
- Because the first step is tricky and perhaps not even necessary as RedHat may have done it for you, you could skip it, and get back to it if you can't get forwarding to work.

Ok, here goes:

Well first of all you will need to recompile the kernel most likely.
I hope your friend can help you with that as it is a tricky process.
There are some tutorials to be found on the web, but even then things can go pretty wrong.

When recompiling the kernel you will need to select IP forwarding/masquerading(NAT) to be compiled in. Read through the subchoices to determine what specific functionality applies to you.
Note: The options you need to select in the kernel configuration depends highly on your system and preferences. Make sure you compile everything your system needs into the kernel (hardware support, filesystem support etc) or your system will not boot!
The first time you do this it will take a lot of time to read through all the options' help files so be prepared for that.(1-2 hours?)

If you've got that covered (by recompiling/installing or if Red Hat has it pre-installed)

You will need to create the script I posted above.
Read through it carefully!
(remember: lines starting with a hash (#) are comments)

Make sure the PRIVATE_IF and PUBLIC_IF are defined correctly.
If you use adsl/cable your PUBLIC_IF is likely ppp0 (check with ifconfig)
Also change PRIVATE_NET to the address space you use for your LAN. ( I use 10.0.0.1 for my gateway, and 10.0.0.X for my LAN)
Replace 10.0.0.0 with your general address space. the /16 allows for all IP's between 10.0.0.0 and 10.0.255.255 to be recognized as private IP's so you can probably leave the /16 (or better: /8) for your setup.

You might want to remove the line: "#Some bastard".... and the line following. I just left it there as an example.

I've yet to use multiple-port forwarding from Outside-To-LAN so I will need to look that up, but you will need something like this:
Code:
/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port [0..79] -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3
/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port [81..442] -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3
/sbin/iptables -t nat -A PREROUTING -p tcp --destination-port [444..65535] -i $PUBLIC_IF -j DNAT --to-destination 10.0.0.3
Assuming 10.0.0.3 is your back-end's IP address.
(You will notice that these three rules forward all ports to your windows machine except ports 80 (http) and 443 (https). This allows traffic to those ports te be handled by processes on the gateway. The rules need to be edited to allow the dchub to run on the gateway, but I don't know which ports that uses.)


Note: Why do you want all traffic to be forwarded to your back-end? Why not let Red Hat block any odd windows vulnerabilities by blocking traffic? All traffic initiated from within your LAN is allowed to go outside, so you can browse/download anyway. Personally I would only forward outside-to-inside the necessary ports for gaming/file-sharing/IM's and such.
That is why I put those "Dungeon Siege" lines in there, so outside gamers could connect to my server behind the firewall.

If, however you don't want to be bothered by looking up all the necessary ports and defining rules for them, then something like the above rules should do the trick


- save the script to disk (preferably to /etc/rc.d/init.d/my_fw_script)
- execute as root:
Code:
chmod +x /path/to/filename/name_of_script
/path/to/filename/name_of_script
(first line makes the script executable, the second executes the script)
(replace /path/to/filename/name_of_script with the path and name you saved the script as)

Now you should have ip forwarding so you can access the internet from your back-end machine.

If it works so far you can make it run at boot (as the last boot-step):
execute as root:
Code:
ln -s /path/to/filename/name_of_script /etc/rc.d/rc5.d/K99my_fw_script
(this line creates a link to your script so it is executed at startup)
Note: IIRC the default runlevel for RedHat is 5. If not, change "rc5.d" to "rcX.d" replacing X with the correct runlevel.

I hope I've covered everything, if not feel free to ask (or if someone wants to add, please do!)
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 02-07-2004, 02:50 PM   #5 (permalink)
Poo-tee-weet?
 
JStrider's Avatar
 
Location: The Woodlands, TX
so yah couldnt even get the computers to talk to each other... and had to reinstall cause i couldnt remember the root password and whatnot....

then i got a dchub working... but i didnt really care for it... so iwanted to try to run the windows one under wine but couldnt get that to work... i think the comp is too old and crappy to run the gui... and im tired of fucking with it...
__________________
-=JStrider=-

~Clatto Verata Nicto
JStrider is offline  
Old 02-07-2004, 03:08 PM   #6 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
What are the specs of that computer?

Linux can be tough to setup for non-desktop uses. Don't give up too soon however as there are many howto's and stuff to help you along.

If you want to try again (especially the 'talk to eachother' part) feel free to post again!
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 02-07-2004, 03:20 PM   #7 (permalink)
Human
 
SecretMethod70's Avatar
 
Administrator
Location: Chicago
I got this working once 2 years ago. I entirely forget how though (although I don't *think* it was as hard as what seems to be described here.

Either way, I just wanted to point out that if you connect a Windows box to the internet through a Linux box that forwards the connection, you will likely have a lot of trouble with online gameplay and such. That's something I didn't know and didn't think of the time that I did this.
__________________
Le temps détruit tout

"Musicians are the carriers and communicators of spirit in the most immediate sense." - Kurt Elling
SecretMethod70 is offline  
Old 02-07-2004, 03:45 PM   #8 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally posted by SecretMethod70
Either way, I just wanted to point out that if you connect a Windows box to the internet through a Linux box that forwards the connection, you will likely have a lot of trouble with online gameplay and such. That's something I didn't know and didn't think of the time that I did this.
True, as are FTP connections (which are a nightmare to 'masquerade').

My setup allows all traffic that originates from my backend / LAN to pass right through, and all replies are automagically returned to my PC. But connections from outside are initially denied.

If you run a game/ftp/web/dcc/kazaa/whatever server on your backend it will receive no traffic as the connections are attempted from outside. That is why I have the 'dungeon siege' section in my config (see my first post) which opens the ports dungeon siege servers use. So that allows me to run a dungeon siege server (which I no longer have, but that's beside the point) behind my firewall.

So any server that uses static ports like most games, webservers and such are easily forwarded by expanding that section for the right ports.
FTP is different in that it allocates dynamic ports. Some work has been done to allow ftp transfers through a firewall, but that does not seem to always work. I need to set my ftp-client to "passive mode" or it will fail.
The same goes for MS netmeeting.

In short you'll have no problems with:
- Game clients (play on other servers)
- Browsing / telnet
- e-mail

You'll have small problems with:
- Game servers (setting up your own behind a firewall)
- web servers / dchub's
- IM clients (ICQ, Trillian, MSN, etc)
- most FTP clients

You'll have large problems with:
- Netmeeting
- FTP clients that don't support "passive transfers" like old versions of Internet Explorer


However, these problems are all prevented if you just forward 'everything' through the firewall like JStrider was planning to do.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 02-07-2004, 03:46 PM   #9 (permalink)
Quadrature Amplitude Modulator
 
oberon's Avatar
 
Location: Denver
Network games will always be tough with a NAT box in between.
__________________
"There are finer fish in the sea than have ever been caught." -- Irish proverb
oberon is offline  
Old 02-07-2004, 03:49 PM   #10 (permalink)
Poo-tee-weet?
 
JStrider's Avatar
 
Location: The Woodlands, TX
maybe ill just get a little linksys router or somethin along those lines...

and the box with linux on it is
amd k6 2 500
128mb ram
2 nics
voodoo 3 3000
__________________
-=JStrider=-

~Clatto Verata Nicto
JStrider is offline  
Old 02-07-2004, 04:16 PM   #11 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally posted by JStrider
and the box with linux on it is
amd k6 2 500
128mb ram
2 nics
voodoo 3 3000
That should be plenty to run a decent X setup, shouldn't it?
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
 

Tags
forwarding, linux, packet


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:32 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360