The TCP/IP core, talks to real and virtual devices, to send and receive packets. TCP/IP doesn't KNOW you have an ethernet card, you have to tell it.
Every TCP/IP machine MUST have the loopback device configured, and it is always 127.0.0.1
Never-the-less, you have to configure it, just the same as you have to configure every device that TCP/IP uses. This is done in /etc/rc.d/rc.inet1 (or other!).
NOTE: eth0 and /dev/eth0 are completely different, but get linked together to be the working device! eth0 is the TCP/IP interface channel, it talks TCP/IP. /dev/eth0 is the card hardware. It talks IRQ, DMA and packets. /dev/eth0 could be controlled, and accessed by any program, "eth0" can only be accessed by the networking kernel code.
lo is a special interface, that doesn't have any hardware. Any IP packet ("datagram") written out to lo, re-appears as a packet-in.
/dev/eth0 is the device driver's filesystem name, that holds the kernel major and minor device numbers. They correspond to the kernel driver code (probably packaged as a module) which can do occasional tasks like initialising the card, and regular tasks like transmitting and receiving packets.
Ethernet is a protocol beneath the TCP/IP protocol (but has evolved with it). It uses ethernet "MAC" addresses, not IP addresses.
The ethernet card, automatically filters out traffic that this host is interested in receiving. This reduces CPU load, because the machine never sees packets that would get ignored anyway.
You can switch the card into "promiscuous" mode, where every packet on the LAN gets through the hardware filter. That is how LAN sniffers work. Also some packets are "broadcast" to every other card on the LAN, using the broadcast MAC address.
You can also make the card behave as though it has several MAC addresses, when the PC looks like several PC's
But now that you know that, you can forget it! Thanks to careful design of the various standards and components, it just happens!
All ethernet cards are much the same, and /dev/eth0 is a common denominator. However NE2000 cards are different from 3COM cards, and Western Digital cards (etc).
The driver that is relevent to you, is selected by you in /etc/conf.modules (or is groped by the kernel at boot time). Then /dev/eth0 is implemented by the loadable module "ne.o", which contains it's own code, but provides the standard Linux interface and drives an NE2000 based card.
All ethernet cards send and receive complete (checksummed) packets, with typically upto 1500 bytes of data. HINT: write your application to use 1024 bytes of data, then allow yourself to add a few bytes to index the contents of your packets, or add your own data headers. Then your data won't get split into multiple packets, and will have more data than headers.
NOTE: If your etherenet card driver is a module, you must start /sbin/kerneld> before it is needed, ie in /etc/rc.d/rc.S and NOT /etc/rc.d/rc.local which is called after /etc/rc.d/rc.inet1
/dev/modem is probably a link to /dev/cua2 or /dev/ttyS2, the serial port. It understands single bytes coming in and out.
IP (and hence TCP/IP), prefers to communicate in complete packets, not bytes, so the SLIP protocol, and sl0 driver, converts between the two. sl0 allows for long delays between bytes, and other serial behavior that TCP/IP doesn't want to know about.
When you establish a connection, on /dev/modem, you then run the slattach() system call, which "converts" a serial line into an IP interface. PPP is a protocol above SLIP, which does lots of extra things, but is basically the same.
You probably run dip or pppd to do the slattach for you, but you could write your own "dip", or even run the components from the command line (ie slattach(1) is a program that calls slattach(2) for you).
LOOPBACK, SLIP, PPP and ETHERNET interfaces, need to be configured to start and stop them, and to set the running parameters.
You have to tell the interface, using ifconfig, what IP address it is, and how to filter in/out BROADCAST addresses.
You then use the route command, you have to tell the TCP/IP core, that the interface is there, and what LAN it is connected to.
To understand this, look at the ifconfig and route commands for the loopback device.
Each interface needs it's own script, or pair of commands in a script. With slackware, this is usually /etc/rc.d/rc.inet1.
If you don't have ethernet, or dial_up running, you can still be a TCP/IP host, by attaching the loopback interface.
Everybody needs the the loopback device, but it still has to be configured in. eg in /etc/rc.d/rc.inet1
/sbin/ifconfig lo 127.0.0.1 /sbin/route add -net 127.0.0.0
That's all there is to it! Maybe other devices take additional parameters, and routing to the default gateway adds a bit, but the rest of it is just shell scripts with lots of extra syntax, that clouds the view of what is actually happening.
Fortunately, the modern ifconfig and route are better at "guessing" the NETMASK (8 bit host part), and broadcast address (host all 1's). IE unless you are something strange, you don't have to specify them or calculate them (saves a lot of shell script lines). See Issue-1 for how to calculate them.
# these two commands bring the eth0 interface to life! # other parameters such as broadcast, netmask may be needed. # ${VARNAME} is a shell varname that you have set, (in the script) # or just put the correct value there. # Maybe the name, if it is in /etc/hosts and /etc/networks IPADDR=192.168.67.11 NETWORK=192.168.67.0 NETMASK=255.255.255.0 /sbin/ifconfig eth0 ${IPADDR} /sbin/route add -net ${NETWORK} netmask ${NETMASK}
Normally, TCP/IP over the ethernet device stays active for the lifetime of the machine. However, you can bring it down with:
/sbin/ifconfig eth0 down
This will be much the same as for eth0, but for eth1.
You may need to decide which card is which ( eg /etc/modules.conf), and whether your box is a router or gateway between the two LANS, (or simply attached to both).
You can use the same FQHN for both, but usually, one would be called jackdaw.lan_67.trix.dircon.co.uk the other called jackdaw.lan_68.trix.dircon.co.uk
/sbin/ifconfig eth0 192.168.67.14 /sbin/route add -net 192.168.67.0 netmask 255.255.255.0 /sbin/ifconfig eth1 192.168.68.15 /sbin/route add -net 192.168.68.0 netmask 255.255.255.0
This is the file that contains the above commands, on a Slackware system.
Some distributions make it much more complicated by putting the parameters in a second file, and using shell scripts to extract those parameters to build and call the real command line.
Some go one step further to allow individual interfaces to be brought up and down seperately, according to the machine run level. This just adds to the complexity of what is rather simple.
You can use /etc/hosts to hold _some_ of the actual numbers, and use names in the calls to ifconfig and route. This is better, but regerettably there is no established system file to hold the netmasks and broadcast addresses.
The route command is used for complicated and blindingly obvious routing. Ie as well as telling TCP/IP that lan_99 is acessed through a gateway on lan_68 (not lan_67), you have to tell it that lan_67 is accessed via the lan_67 interface.
route is also called, so that packets with no known route, get send down a default interface, to a specific gateway/router. IE a packet destined for sunsite.unc.edu, goes to the route table and doesn't know where to go. It isn't on the LAN, and isn't on your ISP's "local" network. So it goes down the default route, to your ISP's gateway, which then knows how to send it.
The following command is run by pppd or dip, but if your machine is only connected by ethernet, and you have a local gateway, you include it in rc.inet1
# GATEWAY="192.128.67.1" # /sbin/route add default gw ${GATEWAY} metric 1
When you connect to the internet, the "default" route will be your ISP's routing gateway. pppd will call route for you.
The calls to ifconfig, route (and slattach as required), are built-in to the pppd binary, or dip binary (and script). You just have to select and specify the correct parameters.
Since you start PPP (or SLIP) using a command script, the commands don't appear in /etc/rc.d/.
When you start PPP, you (usually) need a chat script to do the dialing, and other configuration files. Look in /etc/ppp/.
If it works, great! But if it didn't, what can you do?
Reread your scripts, and run them manually (there is nothing special about the /etc/rc.d scripts, other than they are run at boot time as root).
You can find out what did happen, using the ifconfig and route commands. Without any parameters, they tell you their current view of the world.
This lists all configured interfaces, and their current parameters. It also hows how many packets have been send/received by each.
lo Link encap:Local Loopback inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0 UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1 RX packets:12 errors:0 dropped:0 overruns:0 TX packets:12 errors:0 dropped:0 overruns:0 eth0 Link encap:10Mbps Ethernet HWaddr 00:C0:DF:45:08:DA inet addr:192.168.67.1 Bcast:192.168.67.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 TX packets:0 errors:0 dropped:0 overruns:0 Interrupt:12 Base address:0x300 ppp0 Link encap:Point-Point Protocol inet addr:193.128.226.67 P-t-P:193.128.226.1 Mask:255.255.255.0 UP POINTOPOINT RUNNING MTU:1500 Metric:1 RX packets:494 errors:0 dropped:0 overruns:0 TX packets:498 errors:0 dropped:0 overruns:0
This lists all configured routes, both routes to LAN's and routes to gateways then beyond.
Kernel routing table Destination Gateway Genmask Flags MSS Window Use Iface tdc_gw.dircon.c * 255.255.255.255 UH 1500 0 0 ppp0 192.168.67.0 * 255.255.255.0 U 1500 0 0 eth0 loopback * 255.0.0.0 U 3584 0 1 lo default tdc_gw.dircon.c * UG 1500 0 5 ppp0