FreeBSD NetWorking Basics

xiaoxiao2021-03-06  79

FreeBSD NetWorking Basicsby Dru Lavigne05 / 13/2004

Translation: Perfect Waste People November 10, 2004

Beginners to Unix-like operating systems such as FreeBSD are often stymied by their network settings. Sure, the install process may have set up your NIC for you, but where do you go to view these settings, and how do you proceed if your NIC STOPS WORKING? Since Networking is Such An Integral Part of Computing, this Article Will Demonstrate How To Verify, Configure, And Optimize Your Network Settings. People in New Contact UNIX operating systems (such as FreeBSD) are often destroyed by the network. Of course, you will automatically set your network card when installing the system, but how do you view these settings? What if the network card does not work? The network is one of the important tasks of the calculation, and this article is like you show how to view, configure, and optimize your network settings.

Verifying Your Interface Configuration view card settings If you've come from a Microsoft background, you've probably used either winipcfg or ipconfig / all to verify your network settings at the command line. Unix comes with a similar utility, named ifconfig (for " Interface config "). by Entering this Command, You'll See All of the system's interfaces and their settings. Some Versions Require you to include the -a, or all, switch. If you turn from the Microsoft system to freebsd, then you may Familiar with WiniPCFG or IPCONFIG / ALLs such as network card configuration. The UNIX system provides a similar tool called ifconfig (meaning "interface configuration" interface config). Enter this command, you can see all the network cards in the system and settings. Some versions require you to add -A, all, etc.

% IFCONFIGRL0: FLAGS = 8802 MTU 1500 options = 8 Ether 00: 05: 5D: D2: 19: B7 Media: Ethernet AutoSelect (10baset / UTP) Status: no carrierrl1: flags = 8802 MTU 1500 Options = 8 Ether 00: 05: 5D: D1: FF: 9D Media: Ethernet AutoSelect (10baset / UTP) status: no carriered0: flags = 8843 mtu 1500 inet 192.168.2.12 netmask 0xffffff00 broadcast 192.168.2.255 ether 00: 50: ba: de: 36: 33lo0: flags = 8049 mtu 16384 inet 127.0.0.1 netmask 0xff000000 Your output will vary from this, but will contain similarities. This particular system is not running the default kernel. I've removed the default IPv6, gif, and faith devices from this kernel, so they do not show in the output. Your output may be different from me, but always contain some similar things. This system is not the default core. I removed the default IPv6, GIF, and Faith devices, so they don't display it in the output.

This system does have three physical interfaces (rl0, rl1, and ed0) and the loopback virtual interface (lo0). Different versions of Unix differ in their interface naming convention. For example, Linux uses eth for Ethernet NICs, so would show their names as eth0, eth1, and eth2. BSD uses the driver name for each NIC, allowing you to differentiate between different chipsets and the features available for each driver. to see the documentation for your NIC's driver, read section 4 of its driver manual. Note That you don't include the number of the interface, so Look Up rl instead of rl0: This system has three network cards (RL0, RL1 and ED0), and there is a virtual loop boundary (LO0). Different UNIX versions are different from the naming of the NIC. For example, the Linux system uses ETH to represent an Ethernet card, so the names of these NIC are displayed into Eth0, Eth1, and Eth2. BSD named the NIC with a driver, so you can distinguish the different chips used in different NICs and their respective features. To view your network card driver-related documentation, read the fourth chapter of the driver manual. Note that the name of the manual does not include the serial number of the NIC, so you should check RL instead of RL0:% Man 4 RLRL - Realtek 8129/8139 Fast Ethernet Device Driver

..% Man 4 eded - ethernet device driverWhile this system has three NICs, only ed0 is up and running The two RealTek NICs do not have cables attached, as indicated by the status: no carrier lines Accordingly, only ed0 has an IP Address (192.168.2.12), A Subnet Mask (0xfffffff00), And A Broadcast Address (192.168.2.255). Although three network cards are installed in the system, only ED0 is working properly. Two realtek network cards do not connect to the network cable, as indicated by their status information: no signal lines. Therefore, only ED0 is assigned an IP address (192.168.2.12), subnet mask (0xfffffff00), and broadcast addresses (192.168.255).

That subnet mask is written in hex, as indicated by the beginning 0x. This particular mask is not too hard to translate into decimal, if you remember that each pair of f characters (ff) is equivalent to 255. Thus, the subnet mask Here is 255.255.255.0. if you find a pair of hex numbers That aren't ff (255) or 00 (0), Use bc or the Built-in Calculator To Translate That HEX Pair Into Decimal For You. For Example, IF Your mask is 0xffffe000: The 0X display is as started, and the subnet mask is output with a 16-way format. This mask is not difficult to convert into a decimal, as long as you remember that each group of ff is equal to 255 of the decimal. Therefore, the subnet mask of this network card is 255.255.255.0. If you find that a set of sub-net masks is not FF (255) or 00 (0), you can use the BC or the built-in calculator to convert each set of hexadecimal. For example, if you get the mask is 0xffffe000:% BCBC 1.06Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.This Is Free Software with Absolutely No Warranty.For Details Type `Warranty'.Base = 16E0224 < Ctrl D> Here, I asked bc to translate a base 16, or hex, number as infut (ibase = 16). Remember to communication any letters to uppercase, or you won't get the correct answer. Since E0 is Decimal 224, This Example Mask is 255.255.224.0. Here, I let the BC use a number of courses (or 16) as input (IBASE = 16). Remember to convert all letters into capital, otherwise you will not get the correct result. Because E0 is a decimal 224, the subnet mask in this example is 255.255.224.0.

Verifying Your Default Gateway to check your default gateway Note that ifconfig gives the applicable status, MTU, IP address, subnet mask, broadcast address, and Ethernet (or MAC) address of each interface. However, it does not give the address of the You should notice that ifconfig outputs the usage status of each block, the MTU, IP address, subnet mask, broadcast address, and Ethernet card (or Mac) address. However, it does not output the default gateway address, nor does it specify the DNS server address.

.. To see your default gateway address, use the netstat, or network status, command Include the -r (routing) switch Including the -n switch speeds up the results by skipping name resolution: To view the default gateway address, use the netstat (network State, network status command. Contains the -R (indicating the routing) switch. Use the -n switch to avoid machine name analysis to accelerate queries. % NetStat -RnRouting Tables

Internet: Destination Gateway Flags Refs Use Netif Expiredefault 192.168.2.100 UGS 0 72664 ed0127.0.0.1 127.0.0.1 UH 1 46 lo0192.168.2 link # 3 UC 0 0 ed0192.168.2.12 127.0.0.1 UGHS 0 0 lo0192.168.2. 100 00: 48: 54: 1e: 2c: 76 UHLW 1 0 ed0 1172Note: Linux users can also use the route command to receive similar results The BSD route command works differently; see man route for details However, netstat -rn works.. ON All Operating Systems, Including Linux and Microsoft Operating Systems. Note: Linux users can also use the route command to get similar results. The BSD Route command has a different way of use; see the manual of Route gets details. However, NetStat -Rn works in all systems, including Linux and Microsoft Windows systems.

In your output, look for the line that begins with the word default. The associated IP address is that of your default gateway. Also look at the flags for that entry. Hopefully they indicate U for up and G for gateway. This indicates that you Can Communicate With your Gateway. If The Number in The Use Field Isn't 0, You've Actually Sent Your Gateway That Number Of Packets. In the output of the DEFAULT, you get it. Related IP addresses are your default gateway. At the same time, check the Flags value in this line. In general, u refers to work (UP) and G is a gateway. This indicates that you can communicate with your gateway. If the value in the USE segment is not 0, here is the number of packets you have sent to the gateway.

Finally, The Last Line of this Output Shows The Mac Address of The Default Gateway. Finally, the last line of output shows the MAC address of the default gateway. Verifying Your DNS Settings Check DNS Setting The Resolver Configuration File Should Contain your DNS Settings. You CAN View That File with: Resolver profile should contain your DNS settings. You can view this file like this:

% More resolv.confnameserver 209.226.175.236nameserver 204.101.251.1nameserver 204.101.251.2This particular system contains the IP addresses of three DNS servers. It's a good idea to have the addresses of at least two servers, in case your primary DNS server becomes unavailable This system contains the address of three DNS servers. Insurance, this should at least contain two addresses to defend the DNS server.

While you have Internet access, you should know how to query your ISP's DNS servers and to record the results in a book containing your network settings. This will be invaluable if you ever need to recreate these settings manually. If you do not keep such A Notebook, you can Gather Those Settings from a System That Does Have Working Internet Access. If you are connected to the Internet, you need to know how to get your ISP DNS server and record this information with your network configuration information. Notebook. Once you need to reopeically set this information, this record will be invaluable. If you don't record this information, you can get them from a system that can connect to the Internet.

To Find Out The IP Addresses of Your DNS Servers, Use Dig, The Domain Information Groper. Here, I'll Ask for the NS, or Name Server, Entries for My ISP: To view your DNS server address, use the DIG command (Domain Information Explorer, Domain Information Groper). Here, I will query my ISP name server (NS, Name Server):

% DIG NS SYMPATICO.CA

<< >> DIG 8.3 << >> NS sympatico.ca ;; RES OPTIONS: INIT Recurs defnam dnsrch ;; got answer: ;;; query, status: noerror, ID: 44589; Flags: qr rd Ra; Query: 1, Answer: 4, Authority: 0, Additional: 4 ;; Query Section: ;; sympatico.ca, type = ns, class = in ;; answer section: sympatico.ca. 6H12M33S In ns ns5.bellnexxia.net.sympatico.ca. 6H12M33S in ns ns6.bellnexxia.net.Sympatico.ca. 6H12M33S in ns dns1.sympatico.ca.sympatico.ca. 6H12M33S in ns dns2.sympatico.ca.

;; ADDITIONAL SECTION:. Ns5.bellnexxia.net 9m36s IN A 209.226.175.236ns6.bellnexxia.net 9m37s IN A 209.226.175.237dns1.sympatico.ca 14m7s IN A 204.101.251.1dns2.sympatico.ca 3m56s IN A... 204.101.251.2

; Total Query Time: 46 msec ;; from: dru.domain.org to Server: 209.226.175.236 ;;hen: Sun Apr 11 14:30:14 2004 ;; MSG SIZE SENT: 30 RCVD: 182

Your output will be divided into several SECTIONs. For now, concentrate on the ANSWER SECTION, which contains the answer to your dig query. My ISP uses four DNS name servers, as seen in my answer. Each name server uses an IN (IPv4) Record and A NS (Name Server) Record. However, The Answer Shows The name resolution; you want the ip addresss in Your Name Servers. Your output should be divided For a few chapters. Here, please pay attention to Anser Section because it contains the answer to your DIG query. As I get the answer, my ISP uses four DNS servers. Each server uses an in (IPv4) mark and an NS (Name Server) mark. At the same time, the host name of the name server is output here. You will not use the host name to resolve the host name, you need is the IP address of the name server.

You'll Find Those Names Mapped to IP Addresses in The Additional Section. You can get the IP address corresponding to these hostnames in Additional Section.

.. Dig is also handy if you ever forget the name or IP address of your ISP's SMTP or mail server This time, query for the mx, or mail exchange record Here, I've shown only the ANSWER SECTION for brevity: dig in your ISP is also useful when ISP's SMTP or the receiving server address is very useful. This time, query the EX (Letter Exchange) record. Here, I only show an ANSWER Section:% Dig MX Sympatico.ca (SNIP) ;; Answer Section: Sympatico.ca. 20M34S IN MX 5 MTA2.SYMPATICO.CA.SYMPATICO.CA. 20M34S IN MX 5 MTA3. sympatico.ca.sympatico.ca. 20m34s IN MX 5 mta1.sympatico.ca. (snip) My ISP has three SMTP servers. See that number between the MX and the name of the mail server? that's the prioritynumber. My ISP's mail servers All Have The Same Priority; However, Some ISPS Use Different Priorities. If you ' See the numbers between MX and host names? That is the priority. All SMTP servers in my ISP have the same priority; however, some ISP uses different priorities. If you are like this, you should use the smallest number - it has the highest priority.

Verifying Your DHCP Lease Checks Your DHCP Rental If Your IP SETTINGS ASSIGNED BY A DHCP Server, You Can See All of Your Currentlease. If you get the IP address from the DHCP server, you can view the current rent All information is also available.

The Lease Itself Is Contained Within Curly Brackets. If You Have Several Leases, The One At The Top of the File Is Your Most Recent Lease. Leased (Lease) is included in a set of parentheses. If you have more than one lease, the top one is your last lease.

% More /var/db/dhclient.leaseslease {interface "ed0"; fixed-address 192.168.2.12; option subnet-mask 255.255.255.0; option time-offset -18000; option dhcp-lease-time 345600; option routers 192.168. 2.100; Option DHCP-Server-Identifier 192.168.2.100; Option Domain-Name-Servers 209.226.175.236, 204.101.251.1, 204.101.251.2; Renew 2 2004/4/13 02:13:03 Rebind 3 2004/4/14 23:34:37; Expire 4 2004/4/15 11:34:37; need to configure an interface? Let's say you've just added another NIC to your system. Once your computer reboots, you'll want to verify that the new NIC was recognized. you can use ifconfig and look for an additional interface. you could Also search the boot probe message for found Ethernet addresses. Remember to include A Capital E IN Your Search: Know how to view your interface configuration is a thing, but how to configure an interface? Suppose you have added a network card to the system. When your system restarts, you need to check if the new network card is identified by the system. You can use ifconfig to view new interfaces. You should also check the startup information to get the Ethernet address. Remember to use uppercase E:% grep ethernet /var/run/dmesg.boot rl0: Ethernet address: 00: 05: 5D: D2: 00: 05: 5D: D1: FF: 9ded0: Port 0x9800-0x981F IRQ 10 At Device 11.0 on PCI0IF Your New Nic Is listed, It's ready to be configured - But what if the new nic wasn't Found AT Bootup? The first question, "HAVE I CREATED A CUSTOM KERNEL?" IF SO, CHECK YOUR KERNEL CONFIGURATION FILE; You May Have Removed The Driver Required by The New NIC. If you see the new NIC, then it is ready Accept the configuration - but if you don't find it? You should first ask, are you using a kernel that you have configured? If so, check the kernel profile; you may delete the driver required for this NIC.

If that's not the issue, you may have to reboot and examine your CMOS settings. Have you disabled any IRQs? Do you have enabled onboard devices that you do not use? If so, they may be wasting an IRQ, and there aren ' T any Left over for your new nic. if you do decide to change a cmos setting, record the original value on a piece of paper. Change One Setting, Boot Up and See iF it Made a Difference. REPEAT AS Necessary. If this is not The key to the problem, you may need to restart and check the CMOS settings. Do you disable some IRQ? Do you have some unused onboard devices, and they exhaust all IRQ? If you are sure to modify the CMOS setting, you should record the old information on a piece of paper. Modify a setting, restart and check if it works. Repeat this process if needed. If the NIC is PCI, check your CMOS PnP OS setting. Sometimes changing it from yes to no will resolve the issue. Also, sometimes seating the NIC in another PCI slot solves the problem. Finally, as a last resort, you can determine if IT IS An Irq Problem by Removing All Cards Except The New Nic and Your Video Card. If the NIC Is Recognized, You Have More Cards Than You Have Irqs. If the NIC is a PCI jack, check the PNP OS settings in CMOS. Sometimes this setting is changed to "No" to solve the problem. In addition, sometimes the PCI socket where the NIC is located may solve the problem. As the last means, you can remove all devices other than NIC and graphics cards to check if there is an IRQ conflict. If this allows the system to detect the NIC, you can support the IRQ amount supported by the device installed in your system.

Configuring IP Address Information configure the IP address information Once your NIC is recognized, decide whether to set the IP address information manually or to use a DHCP server. Either method requires a change to /etc/rc.conf. If you prefer, you can use / stand / sysinstall, which will edit this file for you. This is the same utility you used when you installed your FreeBSD system. Once the utility starts, choose Configure, then Networking, and then use your space bar to select Interfaces. Once the system NIC, you need to choose to manually set IP information or use the DHCP server. Both methods need you modify /etc/rc.conf. If you like, you can use / stand / sysinstall. It will help you modify this file. It is the tool you use when you install the FreeBSD system. Start this program, select Configure, then Networking, then use the space bar to select Interfaces. Otherwise, edit /etc/rc.conf Directly Using Your Favorite Text Editor. For Example, THESE LINES STATISSIGN AN IP Address and Subnet Mask to RL0, And Set The Default Gateway: Or, use your favorite editor to modify / Etc / rc.conf. Just like the following lines, static specify the IP address, subnet mask, and default gateway used by RL0.

ifconfig_rl0 = "inet 192.168.2.25 netmask 255.255.255.0" / defaultrouter = "192.168.2.100" Also, if you're using static IP addressing, do not forget to add the IP addresses of your DNS servers to / etc / resolv. Conf. At the same time, if you use a static IP address, don't forget to add your DNS server address to /etc/resolv.conf.

If You Instead Use a DHCP Server To Receive Your IP Address Information, You Only Need To Add One Line To /etc/rc.conf: If you get IP address information through the DHCP server, you only need to be in /etc/rc.conf Add a line:

ifconfig_rl0 = "DHCP" You do not need to add your default router or DNS server addresses, as the lease assigned by your DNS server should include this information. You do not need to set the default router or DNS server addresses because the DHCP server should be assigned Will contain these contents.

When You've Saved Your Changes To /etc/rc.conf, Initialize Your Network Settings: Waiting for you to save /etc/rc.conf, initialize your network configuration: # / etc / netstartnote: if you EVER NEED TO Renew Your DHCP Lease, Use this Command, But Substitution RL0 for the name of Your NIC: Note: If you need to update your DHCP rental period, use the following command, and replace the RL0 with your network card name:

# Dhclient -r rl0Optimizing Your Configuration optimize your configuration Unless you have an extremely old NIC, or you specifically purchased a 100Mbps NIC, your NIC is 10 / 100Mbps. This means it is capable of negotiating a speed of 10 or 100 Mbps. It most likely also negotiates either half-duplex (can not send and receive simultaneously) or full-duplex (can send and receive simultaneously) operation. This negotiation process occurs between the NIC and the hub or switch at the other end of your networking cable. unless You have an older network card, or you specially bought a 100Mbps network card, your NIC is 10 / 100Mbps. This shows that it can choose 10 Mbps or 100 Mbps speed. Typically, it also automatically selects half-duplex (not simultaneously transmitting and receiving data) or full-duplex (can transmit receiving at the same time). It will negotiate this information with the hubs and switches of the other end of your network.

Obviously, 100Mbps at full-duplex is much better than 10Mbps at half-duplex The limiting factor will be the hub or switch;.. Its documentation will indicate its speed and mode of operation If it does not support 100Mbps or full-duplex, You're not getting The MOST OUT OF Your Nic and your networking Experience Will Be Much Slower. Obviously, 100Mbps full-duplex mode is much better than the half-duplex mode of 10Mbps. The hub, the switch determines this mode; its document indicates its working speed and mode. If it does not support 100Mbps or full duplex, you can't experience all your network cards, the network speed will fall a lot.

However, you should also be aware that even if the hub or switch supports 100Mbps and full-duplex mode, the NIC and the hub or switch still renegotiate these values ​​on an ongoing basis. If your NIC is always plugged into the same hub or switch You should also understand that even if the hub, the switch supports 100Mbps and full-duplex mode, network cards and hubs, the switch may still recommends this information on an existing basis. . If your NIC is always connected in the same hub, on the switch, this can help them negotiate to get a higher configuration. Whether you can do this depends upon the driver for your NIC, so carefully read the man 4 for your driver. In my example network, I would be better off unplugging my ed0 and instead using one of the RealTek interfaces. Why? Man 4 ed indicates that this particular driver only supports 10Mbps at half-duplex mode (IEEE 802.3 CSMA). However, man 4 rl indicates that this driver can be configured to use 100Mbps and full-duplex operation. you can do this is up to you NIC driver. Therefore, please read the page of the Page 4 of the Handbook in Chapter 4. In my sample network, I should actually unplug my ED0 and switch to a realtek interface. why? MAN 4 ED shows that this driver only supports 10Mbps and half-duplex mode (IEEE 802.3 CSMA). However, Man 4 RL displays this driver to support 100Mbps and full duplex operations.

Here is an example of the line I would use in /etc/rc.conf: Here is a few lines I am in /etc/rc.conf:

ifconfig_rl0 = "DHCP" ifconfig_rl0 = "100baseTX mediaopt full-duplex" There are several things to make note of here. One, the manpage will indicate which options are available and how to set them. Two, do not try to add a setting That your nic driver doesn't support, as indeicated by Itsmanpage. third, don't change your speted and duplex mode to a value That your hub or switch doesn't support! Here there is a need to indicate. First, the manual tells you which options you can use and how to set them;

To See ifness, I'll Plug My Network Cable INTO RL0 and ISSUE THE COMMAND / ETC / NETSTART. I'll The CHECK OUT The Results: I insert the network cable into the RL0 and run / etc / netstart check the settings I modified. Whether it works. Then I check this result:% ifconfig rl0rl0: flags = 8843 mtu 1500 options = 8 inet 192.168.2.87 netmask 0xffffff00 broadcast 192.168.2.255 ether 00: 05: 5d: d2 : 19: B7 Media: Ethernet AutoSelect (100Basetx ) status: activesuccess! Success! This article covers most of the content of the Configure Ethernet card settings. You should also refer to the "Setting Network Interface Card" chapter in the FreeBSD manual.

In a few articles after I'D Like To Concentrate on Printing. I will concentrate on printing related content.

Dru Lavigne is an instructor at Marketbridge Technologies in Ottawa and the maintainer of the Open Protocol Resource. Dru Lavigne is a school teacher Marketbridge Technologies of Ottawa, and is one of the defenders of Protocol Resource Open.

转载请注明原文地址:https://www.9cbs.com/read-93428.html

New Post(0)