Escolar Documentos
Profissional Documentos
Cultura Documentos
HowNetworkingWorks
ConfiguringNetworkinginLinux
Usingsystemconfignetwork
Networkdebugging
Wirelessnetworking
IPv6
IowaStateUniversityInformationTechnologyServices
Lastupdate2/11/2008byjbalvanz
Networking
NetworkingusestheTCP/IPprotocolbydefault,but
Linuxcanuseotherprotocolstointeractwithother
operatingsystems:
MSNetworking(samba)
NovellNetware(ipx)
AppleShare(netatalk)
NetworkingReferences
MuchmoreinfoonTCP/IPavailableat:
LinuxNetworkAdministrator'sGuidebyDawson,Bautts
andPurdy(O'Reilly)
https://www.redhat.com/docs/manuals/enterpri
se/RHEL-5-manual/Deployment_Guide-enUS/index.html
http://www.freeprogrammingresources.com/tcp.
html
NetworkInterfaces
Allinterfacestreatedasdevices,foundunder
/dev/devname
loloopbackdevice
Usedfortestingandaccessingserversrunningonthe
localmachine.
NamedlocalhostwithIP127.0.0.1
Ethernet/wirelessinterfaces
eth0,eth1,...
Ethernetandwirelesscards
Mostcommonconnectionsoncampus
Driversareusuallyloadedasamoduleduringstartup
(usinginsmod)butsomeolderdriversmayhavetobe
compiledintotheLinuxkerneltoworkcorrectly.Usually
detectedatinstallationunlessyouaddthecardlater.
PPPinterfaces
ppp0,ppp1,...
Pointtopointprotocol,usuallytelephonemodem
AppearswhenyouinvokethePPPclientdaemon,usually
byrunningsomethinglikewvdialorkdial,toconnectto
anInternetserviceprovider
Otherinterfaces
tk0,tk1... Tokenringinterfaces
sl0,sl1... SLIP(serial,usuallymodem,outdatedand
replacedbyPPP)
plip0...
ParallelLineInterfaceProtocol
(parallelport,likeLapLink)
cipebc0...CryptoIPEncapsulation(IPtunnel)
isdn0...
ISDNmodems
ax0,ax1...
AX.25(foramateurradiobuffs)
NamingofParts
NIC:NetworkInterfaceCard,thehardwarethatconnects
themachinetothenetwork(mightbebuiltinto
motherboard,mightbeaPCIorISAorPCCardaddon)
MACAddress:hardwareaddressoftheNIC,assigned
bythecardmanufacturerwhenthecardismade
Ex:00:0a:95:a7:62:d8
IPAddress:32bitaddressrelatingmachinetoits
"physical"locationonthenetwork(alsocalledIPnumber)
IPPacket
ContainsthedatatobetransferredplusMACaddresses
andIPaddressesforbothsourceanddestination
Headerinfo
IPAddresses Actualdatatobetransferred
Headerinfoincludespacketidentifier,packettype,
protocoltobeused,timetoliveandchecksum
Thisstringofbytesis"yelled"ontothesubnet,andthe
routerforwardsitwhereit'ssupposedtogo.
IPNumbers
Eachinterfacemusthaveaunique32bitIPnumber(at
least,onitssubnet)
Usuallywrittenasfour8bitnumbers
129.186.142.36
Firstthreenumbersdeterminethesubnet
Eachsubnethasarouterthattransferspacketstoandfrom
thesubnet
WheredoestheIPNumberCome
From?
localhostisalways127.0.0.1
PPPconnectionsareassignedanIPwhentheyconnect
Ethernet,wirelessandsimilarconnectionsgetanIP
numberinoneoftwoways:
StaticIPnumber
Dynamicaddressing(DHCPorBOOTP)
StaticIPNumber
Assignedbythenetworkadministrator
AtISU,primarilyusedformachinesthatmustbeat
predictablelocations(serverorremoteaccessdesktop)
AtISU,logintohttp://asw.iastate.eduandgotoRequest
forServices>DomainNameService>IPRequestto
requestastaticIPnumber
Alsousedonprivatenetworks(isolatedbehindarouter
withnoDHCP,orinalocationwithnoInternet
connection)
DynamicIPNumbers
Amachineconnectingtothenetrequestsanaddressanda
DHCPservergivesitone
Mostofcampusbuildings(includingresidence)
MostDSLroutersandcablemodems
ManyLinuxbasedrouterprojects
Microsoft'sInternetConnectionSharing(Windows
98+)
PrivateNetworks
PrivatenetworkIPaddressesfallinthefollowingranges:
10.0.0.0through10.255.255.255
172.16.0.0through172.31.0.0
192.168.0.0through192.168.255.0
Aslongasyournetworkisisolatedorconnectedtothe
Internetbyarouter,youcanuseIPnumbersinthisrange.
Assignonetoeachmachineandkeeptrackofwhatyou
use.Justdon'tusethemoncampus!
ConfiguringNetworking
Basicnetworking(firstEthernetcard)isconfigured
duringinstallation
Networkingchangescanbedoneintwoways:
Editconfigurationfiles,restartinterfacewithifdown
ifaceandifupiface(orifconfigifacedownand
ifconfigifaceup)
UsetheNetworkAdministrationTool
systemconfignetwork
NetworkConfigurationFiles
/etc/sysconfig/network
Basicinformationaboutthecomputer;whetherornot
networkingisonandthehostname
/etc/sysconfig/networkscripts/ifcfgiface
Configurationinformationforinterfaceiface,plusifup
andifdownscripts
/etc/hosts
IPnumbersforspecialmachines
/etc/resolv.conf
Infoondomainnameserversandsearchdomains
/etc/sysconfig/network
Setswhetherornotnetworkingison,thehostnameand
(optionally)thegatewaydeviceandIP.
NETWORKING=yes
HOSTNAME=hostname.subdomain.iastate.edu
GATEWAYDEV=eth0
GATEWAY=129.186.144.254
WhenusingDHCP,theDHCPclientwillcreate
thisfileforyou.
Thehostnameshouldalsobein/etc/hostnamefor
compatibility.
/etc/sysconfig/networkscripts
Configurationsforthedifferentnetworkinterfacesare
locatedin/etc/sysconfig/networkscripts/ifcfgiface
Thescriptsifupandifdowncanbeusedtostartandstop
interfaces:
ifup interface
ifdown interface
Changestoconfigurationscanbedonemanuallyorwith
theNetworkConfigurationtool(systemconfignetwork)
we'llshowyoubothbeforewe'redone.
ifcfgeth0,staticIPonisolated
network
DEVICE=eth0
# static IP, do not use a boot protocol
BOOTPROTO=none
# activate interface at startup
ONBOOT=yes
NETWORK=192.168.1.0
NETMASK=255.255.255.0
IPADDR=192.168.1.27
# do not allow users to enable and disable
USERCTL=no
ifcfgeth0,dynamicIPwithDHCP
DEVICE=eth0
# use DHCP for configuration information
BOOTPROTO=dhcp
# activate on startup
ONBOOT=yes
PPPconnections
Forthemostpartyoudon'tneedtomodifyifcfgpppn;if
youusewvdial,Kppporasimilartooltomakeyour
connections,itwillmanagethatfileforyou.
Youmayneedtomodifyifcfgpppnand/ordialingscripts
manuallyifyourPPPservicehasstrangerequirements
(ISU'sdoesn't)oryouhaveacrankymodem
Typicalifcfgppp0(page1of2)
DEVICE=ppp0
NAME=test
# Name in WVDIAL's configuration list
WVDIALSECT=test
# Modem device and serial port speed
MODEMPORT=/dev/modem
LINESPEED=115200
# name used for PAP authentication at dialup
PAPNAME=jbalvanz
# User can activate and deactivate PPP
USERCTL=true
# Do not activate on startup
ONBOOT=no
ifcfgppp0(p.2of2)
# do not force reconnect if connection drops
PERSIST=no
# use this interface as the default route
DEFROUTE=yes
# modify /etc/resolv.conf with host's DNS info
PEERDNS=yes
# do not automatically open PPP on demand
DEMAND=no
# hang up after 10 minutes inactivity
IDLETIMEOUT=600
DomainNames
Usedsoyoucanremembereasynames(like
www.iastate.edu)insteadof129.186.1.122
Whenitdoesn'tknow,yourmachineasksthedomain
nameserver(DNS)whatIPnumbercorrespondstothe
nameithas.
ControlledbytwofilesinRedHatLinux:
/etc/hosts
/etc/resolv.conf
/etc/hosts
Normallyusedonlyonisolatednetworkswithoutdomain
nameservers,orforthosemachinesyouhavetobeableto
connecttoeveniftheDNSisn'tavailable.Onatypical
isolatednetwork:
127.0.0.1 localhost.localdomainlocalhost
192.168.0.1 pavillion
192.168.0.2 jeffs486
192.168.0.10duron fileserver
Secondnamesarecalledaliases
/etc/resolv.conf
TellsLinuxwhatmachinestoaskforDNSinfoifthe
namegivenisn'tin/etc/hosts
YoumaynothavetomakethisifusingDHCPorPPP;
thoseclientscancreate/etc/resolv.confonconnection
Typical/etc/resolv.confforIowaState'snetwork:
searchait.iastate.edu
nameserver129.186.142.200
nameserver129.186.140.200
nameserver129.186.1.200
NetworkingCommands
Mostofnetworkconfigurationcanbedonewithasmall
numberoftextmodecommands:
hostname
ifconfig
route
FromaGUI,youcanusetheNetworkAdministration
Tool(systemnetworkconfig)
hostname
Setsthehostnamein/etc/sysconfig/networkand
/etc/hostname
hostname machinename
Thisisnormallydoneduringstartupbythescript
/etc/rc.d/sysinit;youshouldn'tneedtodoitmanually.
Usetheshorthandname(emperor)insteadofthefully
justifieddomainname(emperor.ait.iastate.edu)
ifconfig
Usedtogetstatisticsandsetconfigurationinfoabout
networkdevices
CommontodistributionsotherthanRedHat(isusedin
Debian,forinstance)sowillprobablybeavailableevenif
you'renotonyourstandardmachines.
Toexaminethesettingsandstatisticsforaninterface,type
ifconfig iface
/sbin/ifconfig iface
ifconfigeth0output
eth0
HwaddristheMACaddressNetRegneeds
inetaddristheIPaddressofthemachine
NoteRXandTX(receiveandtransmit)statistics(usefulindiagnosing
interfaceproblems)
Infoaboutethernetcardhardwareappearsinlastline
Activatinganddeactivating
interfaces
Toactivateaninterface,type
ifconfig iface up
Todeactivateaninterface,type
ifconfig iface down
Settingconfigurationwithifconfig
Type
/sbin/ifconfig iface address netmask nn.nn.nn.nn
Example:
/sbin/ifconfig eth0 129.186.139.205 netmask 255.255.255.0
Settinganaddresstriggersanautomaticup;tochange
IP,bringinterfacedown,thensetaddress
OtheroptionscanbeusedtosetEthernetcardsettings,IP
tunneling,pointtopointconnections,etc.
route
Whichinterfaceandgatewaydoesapacketusetogettoa
particularhost?Theanswerisintheroutingtables.
routeeditstheroutingtables,determiningwhichinterface
packetsusetogettowhichnetworkhost.
routeisnotalwaysinthepath;ifnot,try
/sbin/route
Seeingtheroutingtable
Type
/sbin/route
Genmask
255.255.255.0
255.0.0.0
0.0.0.0
Flags
U
U
UG
Metric
0
0
0
Ref
0
0
0
Use
0
0
0
Iface
eth0
lo
eth0
Itemswithagatewayof*areonthesamesubnetasthis
machine;theydon'tneedagatewaytoreachthem.
Thedefaultroutermustbeonthelocalsubnet,oronasubnet
withanexplicitlydefinedroute.
Notethatthegatewayisdescribedbydomainname,notIP
number.Use/sbin/route -ntogetIPnumbers.
Addingroutesandgateways
route add default gw 129.186.146.254
setsgatewayforalltrafficnototherwiseroutedto
129.186.146.254
setsroutetothenetwork192.168.0.*viadeviceeth1
DoesNOTroutetrafficfromtheisolatednettoother
interfaceyouneedroutedtodothat.
TheNetworkAdministrationTool
akasystem-config-network
AGUItoolfordoingnetworkconfiguration
Reallyjusteditstheappropriatefilesandrunsscriptsto
startandrestartinterfaces,butsomepeoplefindituseful
becauseeverythingisinonebigplace.
GNOME:System>Administration>Network
KDE:Start>SystemSettings>Network
Shell:type
system-config-network &
ConfiguringDevices
FromtheDevicetab
youcanactivateor
deactivateanetwork
interfacewiththe
buttonsatlowerright
Toeditconfiguration
foraninterface,
highlightandclick
Edit;toaddan
interface,clickNew
ConfiguringanInterfacewithSCN
TosetastaticIP
address,turnon
StaticallysetIP
addressesand
entervaluesfor
address,subnet
maskanddefault
gatewayaddress
ModifyingroutingwithSCN
Toaddaroute,click
Addandenterthe
network,netmask
andgateway
addresses(asinthe
routecommand)
Managing/etc/hostswithSCN
TheHoststabisan
interfaceto
/etc/hosts.Click
Newtoaddahost,
andenterIPnumber,
nameandaliases.
ChangingDNSwithSCN
Setmachinehostname
withtheHostnamefield.
Adduptothreedomain
nameserversinthe
PrimaryDNS,Secondary
DNSandTertiaryDNS
fields.
Tospecifythesearch
path(s),enteraSearch
DomainandclickAdd.
DebuggingTools
pingtestconnectiontoamachine
hostgetDNSinformationaboutacomputer
traceroutefollowthepathofrouterstoamachine
netstatseewhatportsareopenandwhatisconnectedto
them
Ping
Teststheconnectiontoamachine
ping hostname
--- dfd94q.its.iastate.edu ping statistics --6 packets transmitted, 6 received, 0% loss, time 5042ms
rtt min/avg/max/mdev = 0.550/0.623/0.685/0.051 ms
Press<Ctrl/C>tostoppinging(it'snotpolite)
host
hostreturnstheDNSinformationaboutadomainname
oranIPnumber.
host -areturnsinformationabouttheDNSservers
returningtheinformationaswell.
traceroute
traceroutetracesthepathfromyourmachinetoaremotehost.
/usr/sbin/traceroute hostname
#/usr/sbin/traceroute www.uiowa.edu
traceroute: Warning: www.uiowa.edu has multiple addresses; using 128.255.56.81
traceroute to www.uiowa.edu (128.255.56.81), 30 hops max, 38 byte packets
1 b11sr1-10-145.tele.iastate.edu (10.10.145.251) 0.467 ms 0.395 ms 0.829 ms
2 b31gb1-lan254-128.tele.iastate.edu (129.186.254.131) 0.441 ms 0.554 ms 0.464 ms
3 b31br2-437.gw.iastate.edu (192.245.179.154) 0.938 ms 0.737 ms 0.714 ms
4 rtr-border-lc.uiowa.edu (198.49.182.17) 11.432 ms 11.547 ms 11.831 ms
5 rtr-core-lc.uiowa.edu (128.255.2.130) 11.686 ms 12.065 ms 11.197 ms
6 lime.weeg.uiowa.edu (128.255.56.81) 12.059 ms 12.668 ms 11.079 ms
Eachlineisa"hop"orrouter.Thethreetimesoneachlineare
timestoreturnfromthatmachineinmilliseconds.Anasterisk
willappearifitisunabletoconnectbeforetimeout.
Netstat
Usedtodeterminenetworkconnectionsbyandtoyour
machine.
netstat
Wireless(802.11?)Networking
Linuxdoessupportwirelessnetworking,BUT...
NotallwirelesscardshaveLinuxdrivers
Therearewaysaroundthis(oni386machines)but
onlysometimes
Toavoidproblemsinconfiguration,checkthatthecard
you'relookingatissupportedbeforeyoubuy
TousePCCardsyoumustalsohavethePCMCIAsupport
loaded(it'saservice)
AddingaWirelessCard
ChooseSystemSettings>Network
ClickDevices,thenNew.
ChooseWirelessconnectionandclickForward.
ChooseOtherwirelesscard,clickForward.
Chooseyouradapterfromthelist,clickForwardthree
times,thenclickApply.
WorkingwithWireless
Onceinstalled,awirelesscardlookslikeanormal
Ethernetcard.
IPaddress,DNS,etc.issetwithipconfig
Channels,etc.setwithiwconfig
/sbin/iwconfig ethN options
Seetheiwconfigmanpageforoptions.Oryoucandoit
allwithsystemconfignetworkinstead.
WirelesswithSCN
Anextratabappears
wheneditinga
wirelessdevice
Foranencrypted
network,entername
underSSIDandkey
below
Morewirelesshelp
ThecurrentWirelessHOWTOislocatedat
http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/
ThepertinentsectionoftheRedHatEnterprisemanualis
at
http://www.redhat.com/docs/manuals/enterprise/RHEL4
Manual/sysadminguide/s1networkconfigwireless.html
Ndiswrapper
SupportforNICs(particularlywireless)thatdon'thave
Linuxdriversavailable
ProvidesaWindowsAPIcompatiblelayerlettingthe
WindowsNDISdriverworkwithLinux
You'llneedtocompilefromsourceandinstallmanually
http://ndiswrapper.sourceforge.net
rfswitch
Manylaptopsallowyoutoswitchthewirelessadapteron
andofftosavepower
Unfortunately,somelaptopsuseasoftwareswitch
whichdoesn'tworkwithLinux!
rfswitchgivesyoucontroloftheradioinsomelaptops
http://rfswitch.sourceforge.net
(MostDelllaptopsuseahardwareswitch,sodon'tneedthis
utility.)
IPv6
ThecurrentversionofIP(IPv4)hasaproblem;itonly
allowsabout4billionaddresses(32bits)
IPv6usesa128bitaddress,allowing
340282366920938463463374607431768211456(three
hundredfortyundecillion)addresses
Therearealsomanyotherimprovementsinsecurityand
efficiency(IPsecisrequired,NATsareunnecessary...)
LinuxSupportforIPv6
Supported(badly)inRHEL4,betterinRHEL5;checkfor
file/proc/net/if_inet6
Supportcanbeaddedwithinsmod ivp6
Someutilitiessupportit,othersnot
AtISU,IPv6addressesarestaticonly,noDHCP,andthe
associatedIPv4addressmustalsobestatic
Howtoandstatusat
http://www.tldp.org/HOWTO/Linux+IPv6HOWTO/