Fedora ifconfig配置网络接口

Fedora ifconfig 是一个用来查看、配置、启用或禁用网络接口的工具,这个工具极为常用的。可以用这个工具来临时性的配置网卡的IP地址、掩码、广播地址、网关等。也可以把它写入一个文件中(比如/etc/rc.d/rc.local),这样系统引导后,会读取这个文件,为网卡设置IP地址。

1、Fedora ifconfig 查看网络接口状态Fedora ifconfig 如果不接任何参数,就会输出当前网络接口的情况

[root@localhost ~]# Fedora ifconfig   


 


eth0 Link encap:Ethernet  HWaddr 00:C0:9F:94:78:0E  


inet addr:192.168.1.88  Bcast:192.168.1.255  Mask:255.255.255.0  


inet6 addr: fe80::2c0:9fff:fe94:780e/64 Scope:Link  


UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  


RX packets:850 errors:0 dropped:0 overruns:0 frame:0  


TX packets:628 errors:0 dropped:0 overruns:0 carrier:0  


collisions:0 txqueuelen:1000  


RX bytes:369135 (360.4 KiB)  TX bytes:75945 (74.1 KiB)  


Interrupt:10 Base address:0x3000  


 


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:57 errors:0 dropped:0 overruns:0 frame:0  


TX packets:57 errors:0 dropped:0 overruns:0 carrier:0  


collisions:0 txqueuelen:0  


RX bytes:8121 (7.9 KiB)  TX bytes:8121 (7.9 KiB)注解: 

eth0 表示第一块网卡, 其中 HWaddr 表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是 00:C0:9F:94:78:0E ; inet addr 用来表示网卡的IP地址,此网卡的 IP地址是 192.168.1.88,广播地址, Bcast:192.168.1.255,掩码地址Mask:255.255.255.0。

lo 是表示主机的回环地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 HTTPD服务器的指定到回坏地址,在浏览器输入 127.0.0.1 就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。

如果想知道主机所有网络接口的情况,请用下面的命令:[root@localhost ~]# Fedora ifconfig -a
如果想查看某个端口,比如查看eth0 的状态,就可以用下面的方法:[root@localhost ~]# Fedora ifconfig eth0
 
2、Fedora ifconfig 配置网络接口

Fedora ifconfig 可以用来配置网络接口的IP地址、掩码、网关、物理地址等;值得一说的是用Fedora ifconfig 为网卡指定IP地址,这只是用来调试网络用的,并不会更改系统关于网卡的配置文件。

如果您想把网络接口的IP地址固定下来,目前有三个方法:一是通过各个发行和版本专用的工具来修改IP地址;二是直接修改网络接口的配置文件;三是修改特定的文件,加入Fedora ifconfig 指令来指定网卡的IP地址,比如在redhat或Fedora中,把Fedora ifconfig 的语名写入/etc/rc.d/rc.local文件中。

Fedora ifconfig 配置网络端口的方法:Fedora ifconfig 工具配置网络接口的方法是通过指令的参数来达到目的的,我们只说最常用的参数:Fedora ifconfig 网络端口 IP地址 hw <HW> MAC地址 netmask 掩码地址 broadcast 广播地址 [up/down]* 实例一:比如我们用Fedora ifconfig 来调试 eth0网卡的地址

[root@localhost ~]# Fedora ifconfig eth0 down  


[root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0  


[root@localhost ~]# Fedora ifconfig eth0 up  


[root@localhost ~]# Fedora ifconfig eth0   


   


eth0 Link encap:Ethernet HWaddr 00:11:00:00:11:11  


inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0  


UP BROADCAST MULTICAST MTU:1500 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:1000  


RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)  


Interrupt:11 Base address:0x3400 

注解:

第一行:Fedora ifconfig eth0 down 表示如果eth0是激活的,就把它DOWN掉。此命令等同于 ifdown eth0;  


第二行:用Fedora ifconfig 来配置 eth0的IP地址、广播地址和网络掩码;  


第三行:用Fedora ifconfig eth0 up 来激活eth0 ; 此命令等同于 ifup eth0  


第四行:用 Fedora ifconfig eth0 来查看 eth0的状态。 

当然您也可以用直接在指令IP地址、网络掩码、广播地址的同时激活网卡,要加up参数。比如下面的例子:

[root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up  


[root@localhost ~]# Fedora ifconfig eth0 down  


[root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0  


[root@localhost ~]# Fedora ifconfig eth0 up  


[root@localhost ~]# Fedora ifconfig eth0   

* 实例二:在这个例子中,我们要学会设置网络IP地址的同时,学会设置网卡的物理地址(MAC地址);
比如我们设置网卡eth1的IP地址、网络掩码、广播地址,物理地址并且激活它。

[root@localhost ~]# Fedora ifconfig eth1 192.168.1.252 hw ether 00:11:00:00:11:11 netmask 255.255.255.0 broadcast 192.168.1.255 up或  


[root@localhost ~]# Fedora ifconfig eth1 hw ether 00:11:00:00:11:22  


[root@localhost ~]# Fedora ifconfig eth1 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up  

其中 hw 后面所接的是网络接口类型, ether表示乙太网, 同时也支持 ax25 、ARCnet、netrom等,详情请查看 man Fedora ifconfig。

3、用Fedora ifconfig 来配置虚拟网络接口

有时我们为了满足不同的需要还需要配置虚拟网络接口,比如我们用不同的IP地址来架运行多个HTTPD服务器,就要用到虚拟地址;这样就省却了同一个IP地址,如果开设两个的HTTPD服务器时,要指定端口号。

虚拟网络接口指的是为一个网络接口指定多个IP地址,虚拟接口是这样的 eth0:0、 eth0:1、eth0:2 ... .. eth1N。当然您为 eth1 指定多个IP地址,也就是 eth1:0、eth1:1、eth1:2 ... ...以此类推。

其实用Fedora ifconfig 为一个网卡配置多个IP地址,就用前面我们所说的Fedora ifconfig的用法,这个比较简单。看下面的例子:

相关推荐