有两种配置Linux网卡的方法:临时配置和永久配置。
1 .临时安置
临时设置网卡(网卡名称为eth0时)的IP地址和子网掩码,重新启动后禁用。
1.1使用ifconfig命令进行配置。 指令如下。
ifconfig eth 0192.168.33.15 net掩码255.255.255.0
配置完成后,使用ifconfig命令验证配置是否成功,并提供:
root@ubuntu:~# ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.33.15 net mask 255.255.255.0 broadcast 192.168.33.255
inet6Fe 80:3360 fab 1:56 ff : feb 5:8 prefixlen 64 scope id0x 20
是以太网8: b 1:563360 b 5:000336008 txqueuelen 1000 (以太网) )
rx包988079字节161803321 (161.8 MB ) ) ) )。
rxerrors0dropped0over runs0frame 0
tx packets 1849659字节258402279 (2.5 GB ) )。
txerrors0dropped0over runs0carrier0collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 net掩码255.0.0.0
inet 6:1 prefixlen 128 scope id0x 10
looptxqueuelen 1000 (本地loopback ) )。
rx包9474363字节997142730 (997.1 MB ) ) ) ) ) ) ) ) )。
rxerrors0dropped0over runs0frame 0
tx packets 9474363字节997142730 (997.1 MB ) ) ) ) ) ) ) ) )。
txerrors0dropped0over runs0carrier0collisions 0
其中,NIClo是本地环回NIC。
使用route命令配置网关。 命令如下:
路由添加默认GW 192.168.33.31
如果未启用网卡eth0,则可以使用命令ifconfig eth0 up启用它; 命令在ifconfig eth0 down中禁用网卡。
2 .永久安置
编辑/etc/network/interfaces文件。 命令如下:
VI/etc/network /接口
按键I或o进入插入模式,编辑完成后使用Esc退出编辑,分别按:wq退出。
例如,此接口的内容可能如下:
#/etc/network/interfaces---- configurationfileforifup (8)、ifdown(8) )。
#已生成的按设备安装程序。
# the loopback接口
自动罗标
iface lo inet loopback
或设置静态IP地址。
auto eth0
iface eth0int静态
地址192.168.33.16
net掩码255.255.255.0
网关192.168.33.31
或默认情况下,在DHCP模式下获取网络配置。
auto eth0
iface eth0 int dhcp
设置后,使用命令行/etc/init.d/networking restart重新启动网络服务,或重新启动并启用计算机。