You are not logged in.

#1 2010-08-21 20:36:12

Kosmonavt
Member
Registered: 2010-02-15
Posts: 100

Software switch on a PC?

Some time ago I was faced some situation when I had to add to machine (worked as gateway and firewall) switch functionality. Non-technical background is rather boring, so here's the interesting part of the task.

Imagine the following situation: there's some PC with many network cards("server"), and a number of "clients" connected to "server". They're connected directly to network interfaces with Ethernet wire. The main goal is 1) to create LAN and 2) effectively gain access to service at "server". Here effectively means that the "server" must be connectable (e.g. via FTP) from "clients" via the same IP address (which is in the same subnet with clients' addresses).

The most straightforward solution is to write many iptables FORWARD rules. Then 1st goal is reached. But there are some nasty drawbacks. First, a lot of rules when there are many many clients (in my case, it was only 2 machines, but even with 4 it would be hell). Second, each "client" sees server with different IP address (that is associated with corresponding interface). Again, with 2 machines it's not a big problem, but it isn't handy at all.

That time I followed the way described, but I feel that it's ugly. Does anyone have an idea, how it can be solved in more convenient and clean way?

Offline

#2 2010-08-21 21:09:56

alexandrite
Member
Registered: 2009-03-27
Posts: 326

Re: Software switch on a PC?

On the server:

echo 1 > /proc/sys/net/ipv4/ip_forward

in rc.local will turn on IPv4 Forwarding, which  will cause the server to forward net traffic without needing all those iptables rules

Offline

#3 2010-08-21 21:24:39

hexanol
Member
From: Canaduh
Registered: 2009-08-04
Posts: 95

Re: Software switch on a PC?

I'm not sure I understand correctly your situation, but if you have some PCs ("clients") directly connected to another PC ("server"), each client being connected to the server via it's own separate UTP wire, i.e. there's a direct connection between each client and the server, with no switch or hub in the way, and you want the client PC to be able to 'talk' to each other, and you want the server to share a unique IP address between all these network interfaces, then you can either:

1. buy a switch... which would be cheaper than buying additional network card on the server, and easier to maintain smile
2. bridge all the network interface together and assign an IP address to the bridge

If you go the second way, you need to install the bridge-utils package. You'll then need to add a bridge interface (brctl addbr br0), add every interface to the bridge (brctl addif br0 <ethX>), up every interface and assign an ip address to the bridge interface. If you want the settings to be persistent, you'll need to do I-don't-know-what (I've only done bridge for testing) in /etc/conf.d/bridges and maybe /etc/rc.conf.

Offline

#4 2010-08-22 09:29:53

Kosmonavt
Member
Registered: 2010-02-15
Posts: 100

Re: Software switch on a PC?

alexandrite wrote:

On the server:

echo 1 > /proc/sys/net/ipv4/ip_forward

in rc.local will turn on IPv4 Forwarding, which  will cause the server to forward net traffic without needing all those iptables rules

AFAIK, it only turns on any forwarding between interfaces, not automatically all-between-all. Still, a thing to check.

hexanol wrote:

I'm not sure I understand correctly your situation, but if you have some PCs ("clients") directly connected to another PC ("server"), each client being connected to the server via it's own separate UTP wire, i.e. there's a direct connection between each client and the server, with no switch or hub in the way, and you want the client PC to be able to 'talk' to each other, and you want the server to share a unique IP address between all these network interfaces, then you can either:

1. buy a switch... which would be cheaper than buying additional network card on the server, and easier to maintain
2. bridge all the network interface together and assign an IP address to the bridge

If you go the second way, you need to install the bridge-utils package. You'll then need to add a bridge interface (brctl addbr br0), add every interface to the bridge (brctl addif br0 <ethX>), up every interface and assign an ip address to the bridge interface. If you want the settings to be persistent, you'll need to do I-don't-know-what (I've only done bridge for testing) in /etc/conf.d/bridges and maybe /etc/rc.conf.

Yes, you correctly understand the situation. The main problem was that then there weren't any router near me, and it was too late to go to a shop. Also it was interesting, how this can be solved without "magic black box". And I didn't need to buy any network cards - I took them from some old PC corpses.

Great thanks for advice, now I know which manpages to read.

Offline

#5 2010-08-22 16:18:25

alexandrite
Member
Registered: 2009-03-27
Posts: 326

Re: Software switch on a PC?

Kosmonavt wrote:
alexandrite wrote:

On the server:

echo 1 > /proc/sys/net/ipv4/ip_forward

in rc.local will turn on IPv4 Forwarding, which  will cause the server to forward net traffic without needing all those iptables rules

AFAIK, it only turns on any forwarding between interfaces, not automatically all-between-all. Still, a thing to check.

I did a similar thing for a class a few quarters ago.  It'll forward IP datagrams one "hop," if you have your routes set up for it to do so.  We had to set up routes manually, but I assumed you'd be able to use some automatic routing daemon or something.  At any rate, I think the "bridge" solution is probably simpler, since your server wouldn't have an IP address for each card.

Offline

Board footer

Powered by FluxBB