Network configuration (简体中文)

From ArchWiki
Revision as of 22:15, 16 January 2008 by SteamedFish (talk | contribs) (Translate from original English document. Not finished.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Network configuration (简体中文)#)



A simple guide to get your network running.


如果你使用 hwdetect ,它应该可以检测你的网卡( NIC )模块并在开机时自动加载。 否则的话,你需要根据你的硬件情况,判断哪些模块是需要加载的。

在网上搜索你的网卡型号,或者尝试着用 Linux LiveCD 来寻找需要的模块的名字──在启动后运行 lsmod 来查看当前加载的所有模块。


# modprobe <模块名>

如果你不想/不能使用像 hwdetect 这样的自动加载工具,你可以把这些模块添加到 /etc/rc.conf 中去,这样你就不用每次开机之后手动加载它。例如,如果 tg3 是你需要的网络模块:

MODULES=(!usbserial tg3 snd-cmipci)

其他常见的模块是: 8139too ( Realtek 芯片); sis900 ( SiS 卡)。

If you use hwdetect it should detect your network card (NIC) module and load it automatically at startup. Otherwise, you will need to know which module is needed for your particular model.

Search the Web for your card model, or try using a Linux LiveCD to find out the name of the needed module - run lsmod to show you all currently loaded modules after booting.

Now when you know which module to use you can load it:

# modprobe <modulename>

If you don't want / can't use some auto-loader like hwdetect you can add it into the modules array in /etc/rc.conf, so you don't need to modprobe it everytime you boot. For example, if tg3 is the network module:

MODULES=(!usbserial tg3 snd-cmipci)

Other common modules are 8139too for cards with the Realtek chipset or sis900 for SiS cards.

配置 IP

DHCP (自动获取) IP

在这种情况下,你需要安装 dhcpd 包(绝大多数情况下都是默认安装好的)。这样编辑 /etc/rc.conf


For this, you need the dhcpcd package (usually already available on most installation). Edit /etc/rc.conf like this:


静态 IP

如果你需要在不使用路由器的情况下,和一台安装 Windows 的电脑分享你的网络连接,确保两台电脑都使用静态 IP ,否则你的局域网将会有问题。


  • 你的静态IP地址;
  • 子网掩码;
  • 广播地址;
  • 你的网关;
  • DNS 服务器(域名服务器)的 IP 地址;
  • 你的域名。

如果你想配置一个内部网络,可以将你的 IP设置成 192.168.*.* ,子网掩码设置成 ,广播地址设置成 。除非你的网络拥有路由器,否则网关地址不重要。参考下面的例子编辑你的/etc/rc.conf ,使用你自己的 IP ,掩码,广播地址和网关:

 eth0="eth0 netmask broadcast"
gateway="default gw"

上面这个例子中, IP 为 ,掩码为 ,广播地址为 ,网关为

参考下面的例子编辑 /etc/resolv.conf ,使用你自己的域名服务器的 IP 和你的域名:

nameserver 61.95.849.8

上面的例子中,两个域名服务器分别为 、 61.95.849.8 。


如果你使用 DHCP 自动获取 IP 地址,但是不想每次启动网络的时候让 DHCP 更改你的 DNS 服务器(域名服务器),在 /etc/conf.d/dhcpcd 中的 DHCPCD_ARGS 中添加 -R 选项。这样会阻止 DHCP 在每次网络启动的时候改写你的 /etc/resolv.conf


If you share your internet connection from a Windows box without a router, be sure to use static IPs on both computers. Otherwise you will have LAN issues.

You need:

  • Your static IP address,
  • The netmask,
  • The broadcast address,
  • Your gateway,
  • Your nameservers' IP addresses,
  • Your domain name.

If you are running a private network, it is safe to use IP addresses in 192.168.*.'* for your IPs, with a netmask of and broadcast address of Unless your network has a router, the gateway address does not matter. Edit /etc/rc.conf like this, substituting your own values for the IP, netmask, broadcast, and gateway:

 eth0="eth0 netmask broadcast"
gateway="default gw"

and your /etc/resolv.conf like this, substituting your nameservers' IPs and your domain name:

nameserver 61.95.849.8

You may include as many nameserver lines as you wish.

If you use DHCP and you don't want your DNS servers to change every time you start your network, be sure to add the "-R" option to DHCPCD_ARGS in /etc/conf.d/dhcpcd (used by in /etc/rc.d/network). This prevents DHCP from rewriting your /etc/resolv.conf every time:



如果因为某些原因, 使用 DHCP 自动获取( dhcpd eth0 )失败,安装 dhclient ( pacman -Sy dhclient ),使用 'dhclient eth0' 代替。

If for some reason dhcpcd eth0 fails, install dhclient (pacman -Sy dhclient) and use 'dhclient eth0' instead.


编辑 /etc/rc.conf ,将 HOSTNAME 设置成你想要的计算机名称:


Edit /etc/rc.conf and set HOSTNAME to your desired computer name:


设置本机域名/ IP

编辑 /etc/hosts ,添加你在 /etc/rc.conf 的 HOSTNAME 选项中填写的东西,按照这样的格式:   localhost.localdomain      localhost    banana

那些带有 localhost 的项是很多程序所需要的

Edit /etc/hosts and add the same HOSTNAME you entered in /etc/rc.conf :   localhost.localdomain      localhost    banana

This format, including the localhost entries is required for program compatibility.


想测试你的设置,可以重启计算机,或者在 root (超级用户)下运行 /etc/rc.d/network restart 。 试着按照这个顺序 ping 一些网络地址:你的网关, DNS 服务器(域名服务器), ISP 服务提供商,以及其他的网络地址。这样可以检查你的网络连接在哪里出了问题。

To test your settings either reboot the computer, or as root, run /etc/rc.d/network restart. Try pinging your gateway, DNS server, ISP provider and other Internet sites, in that order, to detect any connection problems along the way.



无线网络( wlan )配置在 另外一个wiki页面 中。

The wireless (wlan) configuration is the topic of another wiki page.


你可以安装和配置 防火墙 来让你感到更安全。

You can install and configure a firewall to feel more secure. ;-)

即插即用( Ifplugd )

你可以安装这个服务( Ifplugd ),使得当网络接入的时候自动配置网络,当网络断开的时候自动取消配置。这对于笔记本电脑这样的使用移动式的网络适配器的情况很有用,因为他只会在网络实际接入的时候才会配置网络接口。另外一个可能会用得着它的情况是,你需要重启你的网络,可是你既不想重启电脑也不想在 shell (终端)中配置。

它在 [extra] 中,因此安装非常简单:

# pacman -S ifplugd

在默认情况下,它会检查 eth0 设备。更改这个设置(以及更改其他设置,比如等待时间),可以编辑 /etc/ifplugd/ifplugd.conf


# /etc/rc.d/ifplugd start

或者将它加入/etc/rc.conf 的 DAEMONS 列表,这样它就能开机自动启动了。

You can install a daemon which will automatically configure your Ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected. Another use is when you just need to restart the network but don't want to restart the computer or do it from the shell.

Installation is very simple since it's in [extra]:

# pacman -S ifplugd

By default it is configured to work for eth0 device. This and other settings like delays can be configured in /etc/ifplugd/ifplugd.conf.

Start it with

# /etc/rc.d/ifplugd start

or add it into DAEMONS array in /etc/rc.conf.


你可以安装 'ifenslave' 来让你的两块真实网卡绑定同一个 IP 地址。


bond_bond0="eth0 eth1"


MODULES=(... bonding ...)
bond0="bond0 netmask broadcast"


#/etc/rc.d/network restart


You can install 'ifenslave' to bind two real Ethernet cables with one IP address. /etc/conf.d/bonding

bond_bond0="eth0 eth1"


MODULES=(... bonding ...)
bond0="bond0 netmask broadcast"

restart network by

/etc/rc.d/network restart


Swapping computers on the cable modem

Most domestic cable ISPs (videotron for example) have the cable modem configured to recognise only one client PC, by the MAC address of its network interface. Once the cable modem has learnt the MAC address of the first PC that talks to it, it will not respond to another MAC address in any way. Thus if you swap one PC for another (or for a router), the new PC (or router) will not work with the cable modem, because the new PC (or router) has a different MAC address to the old one. To reset the cable modem so that it will recognise the new PC, you must power the cable modem off and on again. Once the cable modem has rebooted and gone fully online again (indicator lights settled down), reboot the newly connected PC so that it makes a DHCP request, or manually make it request a new DHCP lease.

The TCP Window Scaling Issue

TCP packets contain a "window" value in their headers indicating how much data the other host may send in return. This value is represented with only 16 bits, hence the window size is at most 64Kb. TCP packets are cached for a while (they have to be reordered), and as memory is (or used to be) limited, one host could easily run out of it.

Back in 1992, as more and more memory became available, RFC 1323 was written to improve the situation: Window Scaling. The "window" value, provided in all packets, will be modified by a Scale Factor defined once, at the very beginning of the connection.

That 8-bit Scale Factor allows the Window to be up to 32 times higher than the initial 64Kb.

It appears that some broken routers and firewalls on the Internet are rewriting the Scale Factor to 0 which causes misunderstandings between hosts.

The Linux kernel 2.6.17 introduced a new calculation scheme generating higher Scale Factors, virtually making the aftermaths of the broken routers and firewalls more visible.

The resulting connection is at best very slow or broken.

How To Diagnose The Problem?

First of all, let's make it clear: this problem is odd. In some cases, you will not be able to use TCP connections (HTTP, FTP, ...) at all and in others, you will be able to communicate with some hosts (very few).

Warning: dmesg's output is OK, logs are clean and ifconfig will report normal status — and actually everything is normal.

If you can't browse any website, but you can ping some rare hosts, chances are great that you're experiencing this issue: ping uses the ICMP protocol and is not affected by TCP issues.

You can try to use WireShark. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).

How To Fix It? (The bad way)

To fix it the bad way, you can change the tcp_rmem value, on which Scale Factor calculation is based. Although it should work for most hosts, it's not guaranteed, especially for very distant ones.

echo "4096 87380 174760" > /proc/sys/net/ipv4/tcp_rmem

Or you can try to remove one of your RAM sticks (yes, sir).

How To Fix It? (The good way)

Simply disable Window Scaling. Even if Window Scaling is a nice TCP feature, it may be uncomfortable especially if you can't fix the broken router. There are several ways to disable Window Scaling, and it seems that the most bulletproof (which will work with most kernels) is to add the following lines to your /etc/rc.local:

echo 0 > /proc/sys/net/ipv4/tcp_window_scaling

How To Fix It? (The best way)

This issue is caused by broken routers/firewalls, so let's change them. Some users have reported that the broken router was their very own DSL router.

More about it?

This section is based on the LWN article TCP window scaling and broken routers and a Kernel Trap article: Window Scaling on the Internet.

And more recently, some Archers have been hit by this issue:

There are also several relevant threads on the LKML.

Realtek No Link / WOL issue

Users with Realtek 8168 8169 8101 8111 based NICs (cards / and on board) may notice an issue where the NIC seems to be disabled on boot and has no Link light. This can usually be found on a dual boot system where Windows is also installed. It seems that using the offical realtek drivers (dated anything after May 2007) under windows is the cause. These newer drivers disable the Wake-On-Lan feature by disabling the NIC at Windows shutdown time, where it will remain disabled until the next time Windows boots. You will be able to spot if this is issue is affecting you because the Link light will remain off only until Windows boots, during Windows shutdown it will revert back to the Link light being off. Normal operation should be that the link light is always on as long as the system is on, even during POST. This issue will also affect other OS's without newer drivers (eg. Live CD's). Here's a couple of fixes for this issue.

Method 1 - Rollback/Change Win driver

You can rollback your Windows NIC driver to the Microsoft provided one (if available), or rollback/install to an official Realtek driver pre-dated May 2007 (maybe on the CD that came with your hardware).

Method 2 - Enable WOL in Win driver

Probably the best and fastest fix is to change this setting in the Windows driver. This way it should be fixed system wide and not only under Arch (eg. live CD's, other OSes). In Windows under device manager, find your Realtek Network adapter and double click it. Under the advanced tab change "wake-on-lan after shutdown" to enable.

 In Windows XP (example)
 Right click my computer --> Hardware tab --> Device Manager --> Network Adapters --> "double click" Realtek ... --> Advanced tab --> Wake-On-Lan After Shutdown --> Enable.

Method 3 - Newer Realtek Linux driver

Any newer driver for these Realtek cards can be found for Linux on the realtek site. (untested but believed to also solve the problem).