Linux下的网络设置

今天有一台虚拟机需要配置网卡,于是乎我这个对网络只是一无所知的IT女只好硬着头皮学习了一下网卡的配置,继而激发了我学习网络的兴趣。


第一,利用“ ip link show ”查看设备的硬件信息,如下:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 00:25:90:33:9b:be brd ff:ff:ff:ff:ff:ff


第二,利用" ip link set eth0 up"或者 "ifconfig eth0 up" 将 eth0设备启动,现在可以用 ifconfig查看

eth0 Link encap:Ethernet HWaddr 20:6A:8A:A8:8A3F
inet6 addr: fe80::226a:8aff:fea8:8a3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3775 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes: 367314 (358.7 KiB) TX bytes:886 (886.0 b)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1878410 errors:0 dropped:0 overruns:0 frame:0
TX packets:1878410 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4044190217 (3.7 GiB) TX bytes:4044190217 (3.7 GiB)

第三,配置/etc/sysconfig/network-scripts/ifcfg-eth0文件,如果没有这个文件就新建一个。

DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:25:90:33:9B:BF"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="24e4c889-8394-45fd-88e4-82ed66d463c5"
IPADDR=192.168.0.233
NETMASK=255.255.255.0
GATEWAY=192.168.0.1


第四,重启网络服务 “ service network restart ”。然后使用ifconfig查看。如果inet addr的值没有改变,也就是没有ip地址的话,可以用dhclient获取ip:dhclient eth0

eth0 Link encap:Ethernet HWaddr 00:25:90:33:9B:BF
inet addr:192.168.0.233 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::225:90ff:fe33:9bbf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:432417864 errors:30 dropped:0 overruns:0 frame:30
TX packets:528794580 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:243358436829 (226.6 GiB) TX bytes:581659675728 (541.7 GiB)
Interrupt:17 Memory:fbde0000-fbe00000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1878496 errors:0 dropped:0 overruns:0 frame:0
TX packets:1878496 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4044196393 (3.7 GiB) TX bytes:4044196393 (3.7 GiB)



本文出自 “黎静技术博客” 博客,转载请与作者联系!

你可能感兴趣的:(linux,网络,网卡,eth0)