Skip to content

Commit 2a891b3

Browse files
authored
Update ifconfig.md
1 parent 1a51c49 commit 2a891b3

File tree

1 file changed

+128
-120
lines changed

1 file changed

+128
-120
lines changed

command/ifconfig.md

Lines changed: 128 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,128 @@
1-
ifconfig
2-
===
3-
4-
配置和显示Linux系统网卡的网络参数
5-
6-
## 补充说明
7-
8-
**ifconfig命令** 被用于配置和显示Linux内核中网络接口的网络参数。用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。
9-
10-
### 语法
11-
12-
```
13-
ifconfig(参数)
14-
```
15-
16-
### 参数
17-
18-
```
19-
add<地址>:设置网络设备IPv6的ip地址;
20-
del<地址>:删除网络设备IPv6的IP地址;
21-
down:关闭指定的网络设备;
22-
<hw<网络设备类型><硬件地址>:设置网络设备的类型与硬件地址;
23-
io_addr<I/O地址>:设置网络设备的I/O地址;
24-
irq<IRQ地址>:设置网络设备的IRQ;
25-
media<网络媒介类型>:设置网络设备的媒介类型;
26-
mem_start<内存地址>:设置网络设备在主内存所占用的起始地址;
27-
metric<数目>:指定在计算数据包的转送次数时,所要加上的数目;
28-
mtu<字节>:设置网络设备的MTU;
29-
netmask<子网掩码>:设置网络设备的子网掩码;
30-
tunnel<地址>:建立IPv4与IPv6之间的隧道通信地址;
31-
up:启动指定的网络设备;
32-
-broadcast<地址>:将要送往指定地址的数据包当成广播数据包来处理;
33-
-pointopoint<地址>:与指定地址的网络设备建立直接连线,此模式具有保密功能;
34-
-promisc:关闭或启动指定网络设备的promiscuous模式;
35-
IP地址:指定网络设备的IP地址;
36-
网络设备:指定网络设备的名称。
37-
```
38-
39-
### 实例
40-
41-
**显示网络设备信息(激活状态的):**
42-
43-
```
44-
[root@localhost ~]# ifconfig
45-
eth0 Link encap:Ethernet HWaddr 00:16:3E:00:1E:51
46-
inet addr:10.160.7.81 Bcast:10.160.15.255 Mask:255.255.240.0
47-
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
48-
RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
49-
TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
50-
collisions:0 txqueuelen:1000
51-
RX bytes:3607197869 (3.3 GiB) TX bytes:6115042 (5.8 MiB)
52-
53-
lo Link encap:Local Loopback
54-
inet addr:127.0.0.1 Mask:255.0.0.0
55-
UP LOOPBACK RUNNING MTU:16436 Metric:1
56-
RX packets:56103 errors:0 dropped:0 overruns:0 frame:0
57-
TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
58-
collisions:0 txqueuelen:0
59-
RX bytes:5079451 (4.8 MiB) TX bytes:5079451 (4.8 MiB)
60-
```
61-
62-
说明:
63-
64-
**eth0** 表示第一块网卡,其中`HWaddr`表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是`00:16:3E:00:1E:51`
65-
66-
**inet addr** 用来表示网卡的IP地址,此网卡的IP地址是`10.160.7.81`,广播地址`Bcast:10.160.15.255`,掩码地址`Mask:255.255.240.0`
67-
68-
**lo** 是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 httpd服务器的指定到回坏地址,在浏览器输入127.0.0.1就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。
69-
70-
* 第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)。
71-
* 第二行:网卡的IP地址、子网、掩码。
72-
* 第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节。
73-
* 第四、五行:接收、发送数据包情况统计。
74-
* 第七行:接收、发送数据字节数统计信息。
75-
76-
**启动关闭指定网卡:**
77-
78-
```
79-
ifconfig eth0 up
80-
ifconfig eth0 down
81-
```
82-
83-
`ifconfig eth0 up`为启动网卡eth0,`ifconfig eth0 down`为关闭网卡eth0。ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。
84-
85-
**为网卡配置和删除IPv6地址:**
86-
87-
```
88-
ifconfig eth0 add 33ffe:3240:800:1005::2/64 #为网卡eth0配置IPv6地址
89-
ifconfig eth0 del 33ffe:3240:800:1005::2/64 #为网卡eth0删除IPv6地址
90-
```
91-
92-
**用ifconfig修改MAC地址:**
93-
94-
```
95-
ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE
96-
```
97-
98-
**配置IP地址:**
99-
100-
```
101-
[root@localhost ~]# ifconfig eth0 192.168.2.10
102-
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
103-
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
104-
```
105-
106-
**启用和关闭arp协议:**
107-
108-
```
109-
ifconfig eth0 arp #开启网卡eth0 的arp协议
110-
ifconfig eth0 -arp #关闭网卡eth0 的arp协议
111-
```
112-
113-
**设置最大传输单元:**
114-
115-
```
116-
ifconfig eth0 mtu 1500 #设置能通过的最大数据包大小为 1500 bytes
117-
```
118-
119-
120-
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
1+
ifconfig
2+
===
3+
4+
配置和显示Linux系统网卡的网络参数
5+
6+
## 补充说明
7+
8+
**ifconfig命令** 被用于配置和显示Linux内核中网络接口的网络参数。用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。
9+
10+
### 语法
11+
12+
```
13+
ifconfig(参数)
14+
```
15+
16+
### 参数
17+
18+
```
19+
add<地址>:设置网络设备IPv6的ip地址;
20+
del<地址>:删除网络设备IPv6的IP地址;
21+
down:关闭指定的网络设备;
22+
<hw<网络设备类型><硬件地址>:设置网络设备的类型与硬件地址;
23+
io_addr<I/O地址>:设置网络设备的I/O地址;
24+
irq<IRQ地址>:设置网络设备的IRQ;
25+
media<网络媒介类型>:设置网络设备的媒介类型;
26+
mem_start<内存地址>:设置网络设备在主内存所占用的起始地址;
27+
metric<数目>:指定在计算数据包的转送次数时,所要加上的数目;
28+
mtu<字节>:设置网络设备的MTU;
29+
netmask<子网掩码>:设置网络设备的子网掩码;
30+
tunnel<地址>:建立IPv4与IPv6之间的隧道通信地址;
31+
up:启动指定的网络设备;
32+
-broadcast<地址>:将要送往指定地址的数据包当成广播数据包来处理;
33+
-pointopoint<地址>:与指定地址的网络设备建立直接连线,此模式具有保密功能;
34+
-promisc:关闭或启动指定网络设备的promiscuous模式;
35+
IP地址:指定网络设备的IP地址;
36+
网络设备:指定网络设备的名称。
37+
```
38+
39+
### 实例
40+
41+
**显示网络设备信息(激活状态的):**
42+
43+
```
44+
[root@localhost ~]# ifconfig
45+
eth0 Link encap:Ethernet HWaddr 00:16:3E:00:1E:51
46+
inet addr:10.160.7.81 Bcast:10.160.15.255 Mask:255.255.240.0
47+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
48+
RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
49+
TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
50+
collisions:0 txqueuelen:1000
51+
RX bytes:3607197869 (3.3 GiB) TX bytes:6115042 (5.8 MiB)
52+
53+
lo Link encap:Local Loopback
54+
inet addr:127.0.0.1 Mask:255.0.0.0
55+
UP LOOPBACK RUNNING MTU:16436 Metric:1
56+
RX packets:56103 errors:0 dropped:0 overruns:0 frame:0
57+
TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
58+
collisions:0 txqueuelen:0
59+
RX bytes:5079451 (4.8 MiB) TX bytes:5079451 (4.8 MiB)
60+
```
61+
62+
说明:
63+
64+
**eth0** 表示第一块网卡,其中`HWaddr`表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是`00:16:3E:00:1E:51`
65+
66+
**inet addr** 用来表示网卡的IP地址,此网卡的IP地址是`10.160.7.81`,广播地址`Bcast:10.160.15.255`,掩码地址`Mask:255.255.240.0`
67+
68+
**lo** 是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 httpd服务器的指定到回坏地址,在浏览器输入127.0.0.1就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。
69+
70+
* 第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)。
71+
* 第二行:网卡的IP地址、子网、掩码。
72+
* 第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节。
73+
* 第四、五行:接收、发送数据包情况统计。
74+
* 第七行:接收、发送数据字节数统计信息。
75+
76+
**启动关闭指定网卡:**
77+
78+
```
79+
ifconfig eth0 up
80+
ifconfig eth0 down
81+
```
82+
83+
`ifconfig eth0 up`为启动网卡eth0,`ifconfig eth0 down`为关闭网卡eth0。ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。
84+
85+
**为网卡配置和删除IPv6地址:**
86+
87+
```
88+
ifconfig eth0 add 33ffe:3240:800:1005::2/64 #为网卡eth0配置IPv6地址
89+
ifconfig eth0 del 33ffe:3240:800:1005::2/64 #为网卡eth0删除IPv6地址
90+
```
91+
92+
**用ifconfig修改MAC地址:**
93+
94+
```
95+
ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE
96+
```
97+
98+
**配置IP地址:**
99+
100+
```
101+
[root@localhost ~]# ifconfig eth0 192.168.2.10
102+
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
103+
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
104+
```
105+
106+
**启用和关闭arp协议:**
107+
108+
```
109+
ifconfig eth0 arp #开启网卡eth0 的arp协议
110+
ifconfig eth0 -arp #关闭网卡eth0 的arp协议
111+
```
112+
113+
**设置最大传输单元:**
114+
115+
```
116+
ifconfig eth0 mtu 1500 #设置能通过的最大数据包大小为 1500 bytes
117+
```
118+
119+
**其它实例**
120+
121+
```bash
122+
ifconfig #处于激活状态的网络接口
123+
ifconfig -a #所有配置的网络接口,不论其是否激活
124+
ifconfig eth0 #显示eth0的网卡信息
125+
```
126+
127+
128+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

0 commit comments

Comments
 (0)