Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > comp.unix.bsd.openbsd.misc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Very limited port redirection setup with pf not working

Hi,

I have a problem with configuring pf and would very much appreciate
some help.

Some background is needed: I have to migrate some web applications from
one machine to another, and I decided to install an OpenBSD box so I
can give it the name of the old web apps machine over night (in DNS),
and then redirect ports gradually from the old web apps machine towards
the new machine as I migrate the individual web apps living on
individual ports over the course of some days without any impact on the
users.

I won't need any firewall functionality because the entire excercise
happens inside a firewalled environment, and I don't think I'd need any
NAT since I have no one-to-many IP relations involved. It should be a
very straight forward setup with a few lines of pf.conf for all I can
see, but it doesn't work.

The old and new web app machine are say 10.4.11.26 and 10.4.10.235
respectively. Those addresses are usually a 255.255.0.0 network (so,
both in the same network). My OpenBSD box is 10.4.12.142, which usually
also has a 16 bit netmask (meaning, all three would be in the same
network).

I must admit I am not an expert when it comes to routing, so I have put
three network cards into the OpenBSD box and hooked all of them up to
the LAN, and I have configured them as 10.4.11.28/24, 10.4.10.237/24
and 10.4.12.142/24. So I tell the box to treat each part of what
usually is a 16 bit network as a class C (24 bit) network.

I don't know if this is a smart thing to do, but I figured the netmask
only tells the box which network portion is attached to what interface?
Essentially it seems that I achieve exactly what I want, I can
communicate (say, ping) my old web app machine (10.4.11.26, through
network card #1) from the OpenBSD box, and my new web app machine
(10.4.10.235, through card #2) as well, and it can reach all other
clients which are all in the 10.4.12.xxx range.

Vice versa, both web app boxes can ping my OpenBSD box, and my openbsd
box can be reached by clients, say 10.4.12.1 for example.

For short, every machine can talk to the OpenBSD box, and be talked to
from the OpenBSD box, and OpenBSD knows how to route.

Then I made a very small pf.conf:

--- snip ---

ext_if="xl0" # interface for inbound traffic
old_if="xl1" # interface for old web apps machine
new_if="xl2" # interface for new web apps machine
old_ip="10.4.11.26" # old web apps IP for rdr rules target
new_ip="10.4.10.235" # new web apps IP for rdr rules target

set block-policy return

rdr on $ext_if proto tcp to port 80 -> $old_ip port 80

pass in keep state
pass out keep state

--- snip ---

This should, me thought, allow a client (say 10.4.12.1) to connect to
the OpenBSD box itself (10.4.12.142) on port 80 and allow me to
redirect this to the web server on the old web apps machine, port 80
(and later, with each software migrated, to redirect to the new app
servers IP instead).

But it doesn't work - I can't see the web page from a client at
10.4.12.1. In tcpdump -i pflog0 -l when adding "log" to the pass out
and pass in rules, I see that my workstation tries to connect to the
old web server (successfully redirected it seems), like so:

17:11:53.730275 myclient.mydomain.com.1059 >
oldwebsrv.mydomain.com.www: [|tcp] (DF)

but no reply ever seems to come from the old web server, through the
OpenBSD box and back to my client.

I believe that the webserver tries to reply directly to the client at
that point and the packets get dropped by the client because they're
out of sequence or so. But I have no idea how to make this work.

Could anyone with more routing skills kindly offer some advice for the
above scenario and how to best build a machine that allows me to
migrate from one web apps machine to another by bending ports one after
another?

Many thanks,

Carsten
The Netherlands

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-16-2008, 07:02 AM
Stefan Roth
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

<snip>

> but no reply ever seems to come from the old web server, through the
> OpenBSD box and back to my client.
>
> I believe that the webserver tries to reply directly to the client at
> that point and the packets get dropped by the client because they're
> out of sequence or so. But I have no idea how to make this work.


it sounds like you need to set a route from your webserver back to the obsd
box.
stefan.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Hi Stefan, and others,

First, many thanks for your reply.

But sorry, I don't quite understand this (being not an expert with
routing).

I believed that I set a route to allow one machine to reach another.
The point at hand is, my webserver can already reach the OpenBSD box.

Unlike the OpenBSD box, the webserver operates with a 16 bit netmask
for the 10.4. network that itself is in, so it can reach (ping etc) the
OpenBSD box at 10.4.12.142 with no problems. So, if the packets coming
port-redirected from the OpenBSD box would look right, the web server
should already send a reply back to the OpenBSD box as far as I can
see?

Maybe you or someone on the list could kindly explain this proposal and
maybe even help me out with a sample route command for this scenario -
it would be greatly appreciated as I have to alter a production
environment and wouldn't want to bring that down by "trying things
out".

Thanks
Carsten

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Some more info: It appears that the port-redirected packages from the
OpenBSD box never reach the webserver in the first place, although the
OpenBSD box can generally reach the web server! Puzzles me.

Client IP: 10.4.10.234
OpenBSD receiving if (to client): 10.4.10.142
OpenBSD if for redirection to webserver: 10.4.12.237 (xl2)
Webserver if: 10.4.12.235

Connecting from the client to port 80 of the openbsd box gets
redirected to port 80 on webserver fine:

tcpdump: WARNING: pflog0: no IPv4 address assigned
tcpdump: listening on pflog0, link-type PFLOG
10:45:30.690277 10.4.12.234.4399 > 10.4.10.235.80: [|tcp] (DF)

and on the interface itself (different tcpdump run, thats why different
high port)

tcpdump: listening on xl2, link-type EN10MB
10:38:16.914070 10.4.12.234.4388 > 10.4.10.235.80: S
2959675908:2959675908(0) wi

but on the web server the command

tcpdump -i eth0 -l -n | grep 10.4.10.23 | grep -v ssh

which should show an incoming connection from 10.4.10.234 that isn't
ssh, I see nothing incoming at the same time - and that despite being
able to reach

10.4.12.235:80

from the OpenBSD box with lynx or telnet 80.

I am totally puzzled by this.

I am wondering now: I could simplify my setup even more and get rid of
the different subnet masks by using just one network card on the
OpenBSD box, maybe that solves the problem? But is it possible to use
just one network card for port redirect? Like saying in pf.conf
"everything coming in on xl0 on port 80, redirect this to another
machine in the same subnets port 80 via the same interface"?

In that case, I could have one card only as 10.4.xxx.xxx/16 that can
reach all machines at once.

Or do I need two network cards and/or two different target subnets for
port redirection to work?

Many thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Sorry, have an error in my second-to last port. The correct IP
addresses are:

Client IP: 10.4.12.234 OpenBSD receiving if (to client): 10.4.12.142
OpenBSD if for redirection to webserver: 10.4.10.237 (xl2) Webserver
if: 10.4.10.235

Apologies.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-16-2008, 07:02 AM
Jaap Versteegh
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

google@humanprototype.com wrote:
> Hi Stefan, and others,
>
> First, many thanks for your reply.
>
> But sorry, I don't quite understand this (being not an expert with
> routing).

I'm not an expert either but some simple reasoning:
If the webserver returns a packet, it has to know a route to the client.
You say that the webserver knows the OBSD box, but does it know how to reach
the client ?
If not so, maybe the webserver needs the OBSD box to be its router (set as
default gateway or having a routing rule that tells the webserver to send
packets destined for the client network to the OBSD box). I think that is
what Stefan meant to say, no ?

HTH, Jaap
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-16-2008, 07:02 AM
Stefan Roth
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

<google@humanprototype.com> wrote in message
news:1132822831.900534.164920@g47g2000cwa.googlegr oups.com...
> Sorry, have an error in my second-to last port. The correct IP
> addresses are:
>
> Client IP: 10.4.12.234 OpenBSD receiving if (to client): 10.4.12.142
> OpenBSD if for redirection to webserver: 10.4.10.237 (xl2) Webserver
> if: 10.4.10.235


try this on your webserver:
route add default 10.4.10.237

stefan


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Hi,

Thanks for the replies.

Jaap:

> You say that the webserver knows the
> OBSD box, but does it know how to reach
> the client ?


Yes. The webservers at 10.4.12.235 and 10.4.11.26 know 10.4.x.x as a 16
bit network, hence it can reach the clients, which are all 10.4.12.x.x.

The clients are accessing the web server (at least the old one) as part
of daily business so that routing is fine.

Stefan:

Thanks, I understand now what you are suggesting. Still I can't make
the OpenBSD box the default route for the web server - it needs the
default route to be set to the company gateway or some of the web apps
running there will break. I might try this as a last resort thing, but
I can't really risk breaking the apps for the users.

I have throught this through in the meantime and I discover further
flaws in my original plan. E.g. the packets from the client, through
the OpenBSD box to the web server will leave the OpenBSD box on one
interface and come back on another (due to my rather "excotic"
subnetting), this will probably break the statefullness anyway. I don't
think that statefullness spawns over multiple interfaces.

I will now try to use one network card in the OpenBSD box, and try to
use 10.4.x.x/16 on that one so I can address both the client and the
two web servers with one network card and have all machines in the same
subnet. I will then try if port forwarding from the OpenBSD box to the
web server works this way. If that works, its the easier and better
way. If not, I am lost

Will keep you all posted. If anyone knows already that the approach
with one common subnet and port forwarding wouldn't work however, I'd
be happy to hear about it.

Cheers,
Carsten

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Got it! Has to do with routing, but default gateway didn't help.

I'll explain:

I added the default gw as you suggested, but the web server still had a
way of reaching the client directly (by being in the same 10.4.x.x/16
network) so it never used the default gateway to reach the clients.

However, then I added this:

route add -net 10.4.12.0 netmask 255.255.255.0 gw 10.4.12.142

to force all packages coming from clients, going through the OpenBSD
box, and back to the clients on the web server to use the OpenBSD box
as gateway.

This works I think because the route above is more stringent (for a 24
bit subnet) than the 16 bit network direct route it has, and hence ...
it works - I can go, on my client, to http://10.4.12.142 and see the
web page the same way I can do by going to http://10.4.12.235.

Many thanks for all replies.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-16-2008, 07:02 AM
google@humanprototype.com
 
Posts: n/a
Default Re: Very limited port redirection setup with pf not working

Happy too soon. It works now, I can bend ports each way, and I can
reach the web servers from clients directly (and the return traffic
through the OpenBSD box) or through the OpenBSD box entirely. Totally
my desired setup.

But I end up getting only half web pages now. It connects, but pages
are returned half, or miss elements towards the bottom of the page.
Seems that now I run into to some weird "timing" or sequence number
problems with the tcp stack

Lost again ...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:30 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590