文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Network Configuration

Network Configuration

时间:2005-11-17  来源:rickyweiwei

Network Configuration
Most critical settings are stored in the /etc/sysconfig directory.
The configuration file that provides the foundation for others in RHEL 3 networking is /etc/sysconfig/network
The configuration file that provides the foundation for others in RHEL 3 networking is /etc/sysconfig/network. It can contain up to five variables, as described in Table

/etc/sysconfig/network Variables

Variable

Description

NETWORKING

Can be yes or no, to configure or not configure networking.

NISDOMAIN

If you're connected to an NIS network, this should be set to the name of the NIS domain.

HOSTNAME

Sets the hostname of the local computer. If you don't see this variable, it may be set by a DHCP server.

GATEWAY

Sets the IP address for the gateway for your network. If you don't see this variable, it may be set by a DHCP server.

GATEWAYDEV

Sets the network device, such as eth0, that this computer uses to reach a gateway. You won't see this if you have only one network card on your computer.

The /etc/sysconfig/network-scripts Files

 

Table 4-15: /etc/sysconfig/network-scripts Files

File in /etc/sysconfig/network-scripts

Description

ifcfg-lo

Configures the loopback device, which is a virtual device that confirms proper installation of TCP/IP.

ifcfg-*

Each installed network adapter, such as eth0, gets its own ifcfg-* script. For example, eth0 gets ifcfg-eth0. This file includes the IP address information required to identify this network adapter on a network.

network-functions

This script contains functions used by other network scripts to bring network interfaces up and down.

ifup-* and ifdown-*

These scripts activate and deactivate their assigned protocols. For example, ifup-ipx brings up the IPX protocol.

There are several closely related commands which can help you manage networking from the command line interface. I describe a few of these commands in Table 4-16.

Table 4-16: Other Network Configuration Commands

Network Script

Description

ifup, ifdown

These scripts start and stop a network card such as eth0. Naturally, ifup eth0 activates eth0; ifdown eth0 deactivates this device.

dhclient

dhclient activates a connection to a DHCP server for your network. The function of a DHCP server is to lease an IP address. Normally activated during the boot process through the ifcfg-* script in the /etc/sysconfig/network-scripts directory. Supersedes scripts from previous versions of Red Hat Linux, including pump and dhcpcd.

ifconfig

The main network interface configuration utility. Can return or set the network parameters on a network device.

Many values are associated with each network interface. At minimum, each network adapter requires a valid, unique IP address, as well as an appropriate network mask. The Network Configuration utility provides five convenient tabs which you can use to customize each network adapter:
  • Devices:This tab allows you to add a new network adapter or edit a configured adapter. You can revise the name of the adapter, IP address assignments, static routing, and hardware device information. Different devices are configured in the /etc/sysconfig files described earlier.

  • Hardware:This tab lets you modify the IRQ port, memory location, I/O address(es), and DMA channel(s) associated with the adapter. Hardware information is documented in different files in the /proc directory.

    Linux sometimes has trouble recognizing second network adapters; you may need to specify hardware addresses such as the IRQ port.

  • IPsec This tab supports Virtual Private Network connections.[VPN]

  • DNS This tab lets you add the addresses of DNS servers available to network adapters on the given network, which is reflected in /etc/resolv.conf.

  • Hosts This tab allows you to modify the name, alias, and IP address assigned to the specified adapter, which is shown in /etc/hosts.

ifup/ifdown

For each installed network adapter, there is a corresponding ifcfg-* file in /etc/sysconfig/network-scripts. You can activate or deactivate that adapter with the ifup and ifdown commands. Either one of the following commands will activate the eth0 network adapter:

ifup ifcfg-eth0 ifup eth0 

ifconfig

The ifconfig command is used to configure and display network devices. Here is some sample output from this command:

# ifconfig eth0 eth0      Link encap:Ethernet  HWaddr 00:50:56:40:1E:6A          inet addr:192.168.30.2  Bcast:192.168.30.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:11253 errors:0 dropped:0 overruns:0 frame:0          TX packets:1304 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:100          RX bytes:2092656 (1.9 Mb)  TX bytes:161329 (157.5 Kb)          Interrupt:10 Base address:0x10a0


If you don't specify a device, ifconfig shows all network adapters, including the loopback adapter.
The ifconfig command can also be used to configure network interfaces. For example, you can assign a new IP address for eth0 with the following command:
# ifconfig eth0 207.174.142.142

Looking at the output of our command, we successfully changed the IP address on the eth0 interface to 207.174.142.142. But this is not enough, as you should realize that the broadcast address doesn't work with this IP address.

With the right switch, the ifconfig command can modify a number of other settings for your network adapter. Some of these switches are shown in Table 4-17.

Table 4-17: ifconfig Switches

Parameter

Description

up

Activates the specified adapter.

down

Deactivates the specified adapter.

netmask address

Assigns the address subnet mask.

broadcast address

Assigns the address as the broadcast address. Rarely required, since the default broadcast address is standard for most current networks.

metric N

Allows you to set a metric value of N for the routing table associated with the network adapter.

mtu N

Sets the maximum transmission unit as N, in bytes.

-arp

Deactivates the address resolution protocol, which collects network adapter hardware addresses.

promisc[混合模式]

Activates promiscuous mode. This allows the network adapter to read all packets to all hosts on the LAN. Can be used to analyze the network for problems, or
to try to crack messages between other users.

-promisc

Deactivates promiscuous mode.

irq port

Assigns a specific IRQ port.

io_addr address

Assigns a specific I/O address.

netstat -r

The netstat command is used to display a plethora of network connectivity information. The most commonly used option, netstat -r, is used to display local routing tables. Here's a sample netstat -r output:

# netstat -nr Kernel routing table Destination     Gateway         Genmask         Flags MSS Window  irtt Iface 191.72.1.0      *               255.255.255.0   U     40  0          0 eth0 127.0.0.0       *               255.0.0.0       UH    40  0          0 lo 0.0.0.0         191.72.1.1      255.255.255.0   UG    40  0          0 eth0

Did you notice we used a -n flag? -n tells netstat to display addresses as IP addresses, instead of as hostnames. This makes it a little easier to see what's going on.

The Destination column lists networks by their IP addresses. The Gateway column indicates gateway addresses. If the destination is on the LAN, no gateway is required, so an asterisk[*] is shown in this column. The Genmask column lists the network mask. Networks look for a route appropriate to the destination IP address. The IP address is compared against the destination networks, in order. When the IP address is found to be part of one of these networks, it's sent in that direction. If there is a gateway address, it's sent to the computer with that gateway. The Flags column describes how this is done. Flag values are listed Table 4-18

The netstat Flag Indicates the Route

Flag

Description

G

The route uses a gateway.

U

The network adapter (Iface) is up.

H

Only a single host can be reached via this route.

D

This entry was created by an ICMP redirect message.

M

This entry was modified by an ICMP redirect message.

arp as a Diagnostic Tool

The Address Resolution Protocol associates the hardware address of a network adapter with an IP address. The arp command displays a table of hardware and IP addresses on the local computer. With arp, you can detect problems such as duplicate addresses on the network, or you can manually add arp entries as required. Here's a sample arp command, showing all arp entries in the local database:

# arp Address           HWtype  HWaddress           Flags Mask            Iface 192.168.0.121     ether   52:A5:CB:54:52:A2   C                     eth0 192.168.0.113     ether   00:A0:C5:E2:49:02   C                     eth0

If the arp table is empty, you haven't made any connections to other computers on your network. The address column lists known IP addresses, usually on the LAN. The HW Type column shows the hardware type of the adapter, while the HW Address column shows the hardware address of the adapter.

You can use the -H option to limit the output from arp to a specific hardware type, such as ax25, ether, or pronet. The default is ether, which is short for Ethernet.

The arp command can help you with duplicate IP addresses, which can stop a network completely. To remove the offending machine's arp entry from your arp table, use the -d option:

# arp -d bugsy 

This removes all arp information for the host 'bugsy.' To add an arp entry, use the -s option:
# arp -s bugsy 00:00:c0:cf:a1:33
This entry will add the host bugsy with the given hardware address to the arp table. IP addresses won't work in this case.

DHCP Clients

You can set up your computer as a DHCP client. If the system-config-network configuration utility does not work, check the configuration file associated with your network card in the /etc/sysconfig/network-scripts directory. You should not need static IP configuration information, and you should see BOOTPROTO=dhcp.
In any case, if you have a working DHCP server on your network, you can connect your computer to it with the dhclient command.

注意:

Red Hat has used different commands to support DHCP clients in the past, including dhcpcd and pump.

相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载