[Home] [Resume] [Work Responsibilities] [Search Page] [IT Menu]
|
|
Much of what’s involved with Linux networking is best performed at the system administrator level.
Setting up a network connection under Linux is easy with Slackware. You can use the configuration utilities or edit the files by hand. This page explains how to get connected to your network.
Type in the command ifconfig –a to display where ever your network interface card has been supported. If the resulting screen displays eth0 you can move onto configuring your NIC
.
Networking Contents
The preferred way of setting up your network connection is through the use of the netconfig program. Run this as root and you will presented with a series of questions to answer. The program will then create the rc.inet1 file.
You will also need kernel support for your network card. The netconfig program can probe your system for a network card and enable it. Or you can edit /etc/rc.d/rc.modules and select your card.
You can, of course, edit the network configuration files by hand. They are
/etc/rc.d/rc.inet1 and /etc/rc.d/rc.inet2, which are discussed in greater detail below.The netconfig program leads you through the process of setting up networking on your Linux system. When you start netconfig, a series of text windows that take you step by step through the setup of your networking appear.
You must run netconfig as root. You should also be careful about the information you provide, as netconfig will gladly take bad values and configure your system accordingly.NOTE:
The first question is what you’d like for a hostname, such as
yonsen. Next, netconfig asks for a domain name without the dot. Many sites have their own domains, in which case you’d use something like mycompany.com, myuniversity.edu, or myorganization.org.The next question asks if you only plan to use the loopback interface. This greatly simplifies the networking setup, but it won’t configure a machine that contains an Ethernet card and that is connected to a LAN (Local Area Network). For machines that only contain a modem, configuring for loopback only should be fine. If you answer no, you’ll be asked to enter your Linux system’s IP address such as 192.63.5.32.
The next step is to enter the network mask, which depends on whether you have a class A, B, or C network address. For a class C address, the value is 255.255.255.0.
The next step is to enter a gateway address. If you have one, enter it. If not, just press Enter to go on.
If you plan to use the Domain Name Service, you need to enter the IP address of a name server. You can later add more name servers into the file /etc/resolv.conf.
Networking Contents
At a lower level than netconfig, and also more familiar to UNIX administrators, is the ifconfig command (short for interface configuration), which essentially tells the kernel about your Ethernet card and the IP addresses if you’ve not done so already. To see the current state of your system, use the command with no options:
$ ifconfig 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:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:40 errors:0 dropped:0 overruns:0 carrier:0 coll:0
In this case, we’re actually using Linux without a network card or a connection to a network — but Linux thinks it’s on a network using a tool called loopback. Loopback allows applications and daemons that need to communicate via TCP/IP to connect to local resources. The first field contains the name of the network interface, lo (short for — you guessed it — loopback). The MTU value is short for Maximum Transmit Unit, which indicates the largest packet that can be sent over the interface without causing the packet to get fragmented. With a faster network, the MTU is larger. (The loopback interface is typically a fast connection.) With 10Mbps (Mega bits per second) Ethernet, the MTU value would likely be lower.
You can use the ifconfig command to set the IP address you want your network card to use. In the previous example, the loopback interface, 127.0.0.1, always refers to the local machine, so you cannot — and should not even try to — change this IP address. With a network card, though, you can use ifconfig to set the IP address for your system.
Networking Contents
HOSTNAME=`cat /etc/HOSTNAME`
All this line does is figure out what the name of your machine is and hang onto it for later. Make sure that /etc/HOSTNAME contains the name you want.
# Attach the loopback device.
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
These lines are a perfect example of the simplicity of BSD-style inits. We need a loopback device, so we kick one in with ifconfig and add a route to the loopback network. Done. Now we can set up our ethernet...
# Edit for your setup.
IPADDR="111.112.113.114"
NETMASK="255.255.255.0"
NETWORK="111.112.113.0"
BROADCAST="111.112.113.255"
GATEWAY="111.112.113.1"
This block of definitions is where you feed rc.inet1 the numbers it needs to set up an ethernet device. Your IP address you can get from your network administrator. The netmask is almost always going to be 255.255.255.0, unless your machine is at the top of the subnet (in which case you probably don't need this page). "Network" will usually be your subnet, (the first 3 parts of your IP addres) with a zero tacked on as the fourth part. "Broadcast" is usually those same first three parts with a 255 tacked on as the fourth part. And gateway is usually going to be the first machine on your subnet (though it may not be... ask your network admin.)
# Uncomment the line below to configure
your ethernet card.
/sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
Brings up an ethernet device using the settings we specified in that definitions block.
[ Insert block of stuff that whines at
user if no ethernet device was found to initialize ]
# Uncomment these to set up your IP
routing table.
/sbin/route add -net ${NETWORK} netmask ${NETMASK} eth0
if [ ! "$GATEWAY" = "" ]; then
/sbin/route add default gw ${GATEWAY} netmask 0.0.0.0 metric 1
fi
Attach a network to that ethernet device we set up a second ago, and we're done.
Networking Contents
# Constants.
NET="/usr/sbin"
IN_SERV="lpd"
LPSPOOL="/var/spool/lpd"
Just setting some stuff we can refer back to later.. variables love you.
# Start the INET SuperServer
if [ -f ${NET}/inetd ]; then
echo -n " inetd"
${NET}/inetd
else
echo "no INETD found. INET cancelled!"
exit 1
fi
Whenever you run a daemon or server from rc.inet2, it's probably going to be in a block like this one. First we look to see if inetd exists, and if it does, we spit out a notice to the console (with no newline, it just gets tacked onto the line with the rest of the servers being started up). Then we start the daemon. If it isn't found, we whine and complain to the console and bail with an error status. (Most daemons actually should NOT exit rc.inet2 with an error status if they aren't found... but inetd does a lot of stuff.)
Example of one such
sample rc.inet1 file:#! /bin/sh
#
# rc.inet1 This shell script boots up the base INET system.
#
# Version: @(#)/etc/rc.d/rc.inet1 2.00 10/06/1999
#
HOSTNAME=`cat /etc/HOSTNAME`
# Attach the loopback device.
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
# IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the
# eth0 interface.
# Edit these values to set up a static IP address:
IPADDR="192.168.1.10" # REPLACE with YOUR IP address!
NETMASK="255.255.255.0" # REPLACE with YOUR netmask!
NETWORK="192.168.1.0" # REPLACE with YOUR network address!
BROADCAST="192.168.1.255" # REPLACE with YOUR broadcast address, if you
# have one. If not, leave blank and edit below.
GATEWAY="192.168.1.1" # REPLACE with YOUR gateway address!
# To use DHCP instead of a static IP, set this value to "yes":
DHCP="no" # Use DHCP ("yes" or "no")
# OK, time to set up the interface:
if [ "$DHCP" = "yes" ]; then # use DHCP to set everything up:
echo "Attempting to configure eth0 by contacting a DHCP server..."
/sbin/dhcpcd
elif [ ! "$IPADDR" = "127.0.0.1" ]; then # set up IP statically:
# Set up the ethernet card:
echo "Configuring eth0 as ${IPADDR}..."
/sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
# If that didn't succeed, give the system administrator some hints:
if [ ! $? = 0 ]; then
cat << EOF
Your ethernet card was not initialized properly. Here are some reasons why this may have happened, and the solutions:
1. Your kernel does not contain support for your card. Including all the network drivers in a Linux kernel can make it too large to even boot, and sometimes including extra drivers can cause system hangs. To support your ethernet, either edit /etc/rc.d/rc.modules to load the support at boottime, or compile and install a kernel that contains support. 2. You don't have an ethernet card, in which case you should comment out this section of /etc/rc.d/rc.inet1. (Unless you don't mind seeing this error...)
EOF
fi
# Older kernel versions need this to set up the eth0 routing table:
KVERSION=`uname -r | cut -f 1,2 -d .`
if [ "$KVERSION" = "1.0" -o "$KVERSION" = "1.1" \
-o "$KVERSION" = "1.2" -o "$KVERSION" = "2.0" -o "$KVERSION" = "" ]; then
/sbin/route add -net ${NETWORK} netmask ${NETMASK} eth0
fi
# If there is a gateway defined, then set it up:
if [ ! "$GATEWAY" = "" ]; then
/sbin/route add default gw ${GATEWAY} netmask 0.0.0.0 metric 1
fi
fi
# End of rc.inet1
Networking Contents
The files that control TCP/IP configuration are stored in the /etc directory. When you first set up Linux and are asked about machine names and domain names, this information is sent to the /etc/hosts file, which we discussed previously. While you don’t need to mess with this file if you’re connected to the Internet (it does many of the same things that a Domain Name Server does), it’s a good thing to place the names of essential servers in this file. And if you’re not connected to the Internet but you are maintaining a small network, this is the place to store the IP addresses for the workstations on your system. (Again, this could be done via a DNS on your local system, but it’s a lot easier to use the /etc/hosts file.)
Another file to check is the /etc/networks file, which is used to configure different networks in the TCP/IP subsystem. This file is summoned when the system launches, and DNS servers handle its functions if you’re working on the Internet. Again, if you’re not connected to the Internet but you want to have subnetworks and such (you really don’t; we’re speaking hypothetically here if you’re working on a small network), you’d use this file instead of a DNS.
Networking Contents
Check if the network card is already configured by typing ipconfig. If the result shown on the screen contains eth0, your network interface card is already configured and supported.
If not, use command vi /etc/rc.d/rc.modules. Search for the entry for your card and remove the # from that line. Save and exit this file.
Change the HOSTNAME of the computer. Other computers will ping this name
Use vi to modify the networking script rc.inet1 by typing vi /etc/rc.d/rc.inet1
Remove the # character in front of those lines which begin with
IPADDR= 192.168.1.3
NETMASK= 255.255.255.0
BROADCAST= 192.168.1.225
GATEWAY= 192.168.1.100
Edit the host file vi /etc/hosts
192.168.1.3 server.home.com server
192.168.1.2 workstat.home.com workstat
192.168.1.1 livingroom.home.com livingroom
The file can be opened from Xexplorer but single clicking. Changes made and then saved.
All of the above except point 5 can be done automatically by typing netconfig at the prompt. Answer the questions and the configuration files manually editted above will be automatically written to the appropiate files.
Where as in Yilins method the vi /etc/rc.d/rc.modules is editted to display the correct NIC this file is not touched when running the netconfig program. It creates another file called rc.netdevice in the /etc/rc.d directory.
The host file vi /etc/hosts still needs to be editted with the IP addresses and names of the other computers on the network.
Networking Contents