五、更“高级”的网络配置
我猜测,这部分网络配置方法适用于大多数linux发行版(纯属猜想,没经过实证)。
(1) 命令行即时配置(重启失效)
Ip地址配置
#ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
Gateway配置
# route add default gw 192.168.30.1 eth0
DNS Server只能通过修改系统文件进行配置
(2) 系统配置文件修改(重启仍有效)
Ip地址配置
所需修改文件为:/etc/sysconfig/network-scripts/ifcfg-interface-name(其中interface-name可能是eth0,wlan0等网卡的名称)
DEVICE=eth0 #物理设备名
IPADDR=192.168.1.10 #IP地址
NETMASK=255.255.255.0 #掩码值
NETWORK=192.168.1.0 #网络地址(可不要)
BROADCAST=192.168.1.255 #广播地址(可不要)
GATEWAY=192.168.1.1 #网关地址
ONBOOT=yes # [yes|no](引导时是否激活设备)
USERCTL=no #[yes|no](非root用户是否可以控制该设备)
BOOTPROTO=static #[none|static|bootp|dhcp](引导时不使用协议|静态分配|BOOTP协议|DHCP协议)
Gateway配置
修改配置文件:/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=Aaron
GATEWAY=192.168.30.1
(尚不清楚与IP配置中的网关设置有何关系)
DNS Server配置
配置文件在/etc/resolv.conf下面。
nameserver 202.109.14.5 #主DNS
nameserver 219.141.136.10 #次DNS
search localdomain
(3) 网络连接方式配置
方式1:网卡通过DHCP 自动获取IP 地址
# 修改文件/etc/network/interfaces如下
#-------------------------------------------------------------------------------
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
auto lo # 开机自动激lo接口
iface lo inet loopback # 配置lo接口为环回口
# The primary network interface (配置主网络接口)
auto eth0 #开机自动激活eth0接口
iface eth0 inet dhcp #配置 eth0接口为DHCP 自动获取#-------------------------------------------------------------------------------
# 重启网络
方式2:网卡静态分配 IP 地址
同样修改/etc/network/interfaces,从auto eth0之后与上步不同:
auto eth0 #开机自动激活eth0接口
iface eth0 inet static #配置 eth0接口为静态设置IP 地址
address 10.16.3.99
netmask 255.255.255.0
network 10.16.3.0
broadcast 10.16.3.255
gateway 10.16.3.1
####################################################
## dns-* options are implemented by the resolvconf package, if installed(DNS 设置)
#dns-nameservers 61.153.177.196 61.153.177.197
#dns-search fireteam.org
####################################################
#sudo gedit /etc/resolv.conf
##设置DNS server(可以设置多个)
#nameserver 192.168.1.1
####################################################
#-------------------------------------------------------------------------------
$ sudo /etc/init.d/networking restart # 重启网络
方式3:PPPoE宽带拨号配置
#sudo pppoeconf #开启设置进程
#sudo pon dsl-provider #首次设置后的手工拨号
#sudo poff #手动断线
#plog 和 ifconfig ppp0 #查看连接情况
方式4:通过无线局域网接入互联网
#lspci #查看无线网卡型号
#iwconfig eth0 txpower on #打开无线网卡电源
#iwlist eth0 scan #检索区域内的无线网络
#iwconfig ath0 essid "linksys" #连接无线网络
#iwconfig ath0 essid "TP-LINK" key 1234-5678-9
#dhclient ath0 #设置无线网卡采用 dhcp方式自动获取ip
(4) 相关命令
重启网络
#service network restart
#/etc/init.d/network restart
开关网络
#ifdown eth0
#ifup eth0
#ifconfig eth0 down
#ifconfig eth0 up
(5) 系统图形界面工具
BT5中网络连接和配置图形界面工具是上文提到的wicd network manager,功能比较有限。此外,Ubuntu11.10中的网络配置工具功能较好。这两者都简单易用,因此这里不做过多说明。
