您的位置:首页 > 运维架构 > Linux

ifconfig命令详解

2016-03-24 10:29 471 查看
一、简单介绍
[root@nginx ~]# ifconfig
eth0(第一张网卡,第二张就是eth1)
Link encap:Ethernet(封装方式-以太网) HWaddr 08:00:27:23:43:11(MAC地址)
inet addr:192.168.11.32(IP) Bcast:192.168.11.255(广播) Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe23:4311/64 Scope:Link (IPv6不用管)
UP(当前状态) BROADCAST RUNNING MULTICAST MTU:1500(最大存储单元,一次传输最大包) Metric:1
(接收的包)RX packets:275960 errors:0 dropped:0 overruns:0 frame:0
(发送的包)TX packets:19786 errors:0 dropped:0 overruns:0 carrier:0
co llisions:0(冲突数,不为0可能网络存在故障) txqueuelen:1000(缓冲器长度)
RX bytes:19362794 (18.4 MiB) TX bytes:2371933 (2.2 MiB)

lo是本地环回地址,用于本地通信:
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:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
二、用法
NAME
ifconfig - configure a network interface

SYNOPSIS
ifconfig [interface]
ifconfig interface [aftype] options | address ...
OPTIONS
interface
The name of the interface. This is usually a driver name followed by a unit number,
for example eth0 for the first Ethernet interface.

up This flag causes the interface to be activated. It is implicitly specified if an
address is assigned to the interface.

down This flag causes the driver for this interface to be shut down.
三、常用使用案例:
(1)[root@nginx ~]# ifconfig eth0 查看eth0的相关信息

(2)[root@nginx ~]# ifconfig eth1 192.168.11.35 broadcast 192.168.11.255 netmask 255.255.255.0 配置IP地址,临时生效(一般去/etc/sysconfig/network-scripts下配置)

(3) ifconfig eth0 down/up 临时开启或关闭网卡。

(4)[root@nginx ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 网卡设备的名称
TYPE=Ethernet 封装类型
UUID=eb80df38-3ca2-4cd0-87d6-f38c3054d092
ONBOOT=yes 是否激活网卡,必须打开
NM_CONTROLLED=yes
BOOTPROTO=none 设置IP启动的方式,有static DHCP 不使用任何方式
HWADDR=08:00:27:23:43:11 MAC地址
IPADDR=192.168.11.32 IP
PREFIX=24 掩码
GATEWAY=192.168.11.254 网关
DNS1=61.128.128.68 DNS
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
该配置文件修改完成,需要重启网络服务:[root@nginx ~]# service network restart
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息