📄 linux-ethernet.html
字号:
<P>Basically, if your network has machines that are assigned IP addressesthat are 192.168.1.*, you represent the whole network with 192.168.1.0. Ifyour network's machines have IP addresses of 192.168.2.*, then your wholenetwork would be represented by 192.168.2.0 and you would type <TT>routeadd -net 192.168.2.0 netmask 255.255.255.0 eth0</TT> in order to get yourLinux machine to contact the rest of the network.</P><P>That should also work for networks with no hubs, if you connect thecomputers all to each other using those RJ-58 cables (the ones thatlook like TV wiring). I haven't tried it myself but few people usethat kind of setup these days.</P><P>All of the above will allow you to contact hosts within yournetwork. Now you have to be able to contact hosts outside your ownlocal network, especially those on the Internet. You'll have toconfigure a gateway, a machine that's connected to the Internet andthat is willing to share its connection with you. For example, if themachine with the IP address 192.168.1.5 is your gateway to theInternet, you would type this (as root) to send requests for addressesthat are out of your network:</P><PRE>route add default gw 192.168.1.5 eth0</PRE><P>If you are connected to the Internet through a dialup connection usingPPP (which most people are), you would do something different, dependingon what machine the Internet connection is running off of. If the machineyou're working on is the machine that's connected to the Internet throughPPP, then you would type something like this:</P><PRE>route add default ppp0</PRE><P>That will configure your system to send requests for packets that arenot in your network to the Internet through your modem. (I hope you'restill following along; if you don't understand I'm not doing a goodjob...)</P><P>You might want to use <AHREF="http://sunsite.unc.edu/LDP/HOWTO/mini/IP-Masquerade.html">IPMasquerading</A>, a way to share your Internet connection with others onyour network. The way it basically works is when a request is sent from amachine within your network, your machine takes a look at it and if it's"addressed" to an Internet address, your machine sends thepacket out through your connection, whether it be Ethernet or PPP.</P><P>If you've got a host within your LAN that's your gateway to theInternet, then you would use <TT>route add default gw 192.168.1.5</TT>, if192.168.1.5 is the IP address of the gateway. When your connection isshared this way instead of IP masquerading, each machine on the network(known as a <B>node</B>) has its own IP address on the Internet.</P><A NAME="startup"></A><H3><A NAME="4">Putting IP Assignment and Routing in Startup</A></H3><P>The information about routing and your IP address on your Ethernetnetwork would be very inconvenient to type in every single time you wantto be connected to the rest of the network, so we'll put it in your systemstartup files.</P><P>One easy (but very sloppy) way is to put the following examplelines in the file <TT>/etc/rc.d/rc.sysinit</TT>:</P><PRE>route add -net 192.168.1.0 eth0ifconfig eth0 192.168.1.1 up</PRE><P>I don't recommend doing it that way, but it's quick, it's simpleand it's almost guaranteed to work. Should you choose to go that route(no pun intended), put the lines at the bottom of the file<TT>rc.sysinit</TT>. The right way to do it would be to use the<B>linuxconf</B> program in Red Hat for your networksettings. Alternatively you can edit <TT>/etc/sysconfig/network</TT>,<TT>/etc/sysconfig/network-scripts/ifcfg-eth0</TT>, and<TT>/etc/hosts</TT>. If you're a true beginner, go ahead and use<B>pico</B> to edit these text files if you have no experience withUnix editors such as <B>vim</B> or <B>emacs</B>.</P><P>Your <TT>/etc/sysconfig/network</TT> file may look something likethis:</P><PRE>NETWORKING=yesHOSTNAME=methuselah.lanDOMAINNAME=lanGATEWAY=192.168.1.5GATEWAYDEV=eth0FORWARD_IPV4=noTIMESERVERATBOOT=noTIMESERVERTYPE=ntpTIMESERVERHOST=(none)TIMESERVERRESYNC=(none)</PRE><P>And your <TT>/etc/sysconfig/network-scripts/ifcfg-eth0</TT>:</P><PRE>DEVICE=eth0IPADDR=192.168.1.1NETMASK=255.255.255.0NETWORK=192.168.1.0BROADCAST=192.168.1.255ONBOOT=yes</PRE><P>Finally, your <TT>/etc/hosts</TT>:</P><PRE>127.0.0.1 localhost localhost.localdomain192.168.1.1 methuselah.lan methuselah</PRE><P>(Something else to note about <TT>/etc/hosts</TT> is that it mightbe the reason that your sendmail or Samba startup is slow on bootup;because it can't figure out what to do with the hostname that you setfor your computer.)</P><!-- We need some info here about DHCP on boot up. I will add itlater, some time.><P>The equivalent I found on Slackware a while back was that you canjust edit <TT>/etc/rc.d/rc.inet1</TT> (or the other rc.inet* file) andit will set it for you automatically. You specify the values ofcertain things like your IP address and broadcast address (and more,of course).</P><P>So if you're going to edit one of those files, just go ahead and useyour favorite text editor (pico, vim, vi, emacs, joe, jed; the list goeson).</P><A NAME="winconfig"></A><H3><A NAME="5">Windows 95 Configuration</A></H3><P>On the Windows 95 machine, if you have one on the network, start byclicking on the Start button, then going to <B>Settings</B>, then<B>Control Panel</B>, and finally <B>Network</B>.</P><P>In the Network dialog box, if you haven't already, add a TCP/IP servicefor your Ethernet card, if you haven't already. Highlight TCP/IP for yourEthernet adapter, and click on the Properties button. Fill in theinformation that you need, such as the gateway IP address (the Linux boxif it's running IP masquerading), the nameserver (your ISP's nameserver),the IP address assigned to your machine within your network (such as192.168.1.2), and any other stuff you might have to fill in.</P><P>You can also run <B>winipcfg</B> to see if you currently have an IPaddress on the network.</P><P>That's about all I know about setting up the Windows box, so let's moveon. Hopefully you have whatever other machines (nodes) on the networkalready set up.</P><A NAME="testconnect"></A><H3><A NAME="6">Testing Your Connection</A></H3><P>To test if your connection works, try pinging another host on yournetwork. Let's say your machine is 192.168.1.1 and the other machine, theone you're going to ping, is <B>192.168.1.2</B>. This is what you'd typeto start pinging the host:</P><PRE>ping 192.168.1.2</PRE><P>If lines periodically appear and look something like this, yourconnection works:</P><PRE>64 bytes from 192.168.1.2: icmp_seq=0 ttl=32 time=1.2 ms64 bytes from 192.168.1.2: icmp_seq=1 ttl=32 time=1.0 ms64 bytes from 192.168.1.2: icmp_seq=2 ttl=32 time=1.0 ms64 bytes from 192.168.1.2: icmp_seq=3 ttl=32 time=1.0 ms64 bytes from 192.168.1.2: icmp_seq=4 ttl=32 time=1.1 ms</PRE><P>To stop pinging, type Control-C (Ctrl+C) to get back to the prompt.</P><A NAME="othersources"></A><H3><A NAME="7">Other Sources of Information</A></H3><UL><LI><A HREF="http://sunsite.unc.edu/LDP/HOWTO/Ethernet-HOWTO.html" TARGET="_top">Linux Ethernet-HOWTO</A> - Hardware info</LI><LI><A HREF="http://sunsite.unc.edu/LDP/HOWTO/NET-3-HOWTO.html" TARGET="_top">Linux NET-3-HOWTO</A> - Network configuration info</LI><LI><A HREF="http://sunsite.unc.edu/LDP/HOWTO/mini/IP-Masquerade.html" TARGET="_top">IP Masquerading mini-HOWTO</A> - Sharing your Internet connection with other computers within your network</LI></UL><A NAME="books"></A><H3><A NAME="8">Related Books</A></H3><OL><LI><A HREF="http://www.amazon.com/exec/obidos/ASIN/1565924002/joshslinuxguide" TARGET="_top">Linux Network Administrator's Guide (2nd Edition)</A> - Freely available in print.</LI></OL><HR><P>If you have trouble and are wondering how to solve your problem, eithersolve it yourself and give me a summary of your scenario, oralternatively, <A HREF="mailto:jgo@local.net">ask for help</A>. And, asusual, suggestions are always welcome.</P><HR><P><B><FONT SIZE="-1">Copyright © 1997-2000 <AHREF="mailto:jgo@local.net">Joshua Go (jgo@local.net)</A>. All rightsreserved. Permission to use, distribute, and copy this document ishereby granted. You may modify this document as long as credit to meis given.</FONT></B></P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -