网络接口 (interface) 是网络硬件设备在操作系统中的表示方法,比如网卡在 Linux 操作系统中用 ethX, 是由 0 开始的正整数,比如 eth0,eth1...... ethX.而普通猫和 ADSL 的接口是 pppX,比如 ppp0 等;
机器中所有可用网卡,名字,配置文件:
dmesg | grep eth :可以看到系统启动时,网卡启动的信息及相应网卡的名字,然后就可以手动添加相应的 / etc/sysconfig/network-scripts/ifcfg-ethX 文件对网卡进行配置
ifconfig -a : 查看所有处于激活状态和终止状态的网卡及相应信息
cat /proc/net/dev : 查看所有虚拟的 eth 文件
/dev/eth0,/dev/eth1 之类的文件在 dev 目录下找不到:在很多 Unix 操作系统中个,网络设备会出现在 / dev 目录下.但是在 Linux 下不是这样的.在 Linux 中,网络设备是被动态创建的,并不需要在 / dev 目录下生成设备文件.大部分的网络设备都是在初始化和加载硬件的时候被设备驱动程序自动创建.比如:ethernet 设备驱动器在加载 ethernet 硬件的时候按顺序创建 eth[0..n] 网卡接口,第一个 ethernet 卡变成 eth0,第二个 ethernet 卡变成 eth1.这在 Redhat 6.0 安装盘的 / doc/HOWTO 目录下的 NET-3-HOWTO 中定义.可以通过虚拟文件:/proc/net/dev 来查看被配置好的 ethernet 设备属性.In many Unix operating systems the network devices have appearances in the /dev directory. This is not so in Linux. In Linux the network devices are created dynamically in software and do not require device files to be present. In the majority of cases the network device is automatically created by the device driver while it is initializing and has located your hardware. For example, the ethernet device driver creates eth[0..n] interfaces sequentially as it locates your ethernet hardware. The first ethernet card found becomes eth0, the second eth1 etc."This was quoted from NET-3-HOWTO in the /doc/HOWTO directory of my RH 6.0 Install cdrom. You can see the settings for configured ethernet devices in the /proc/net/dev'pseudo file
网络配置相关命令:
/bin/hostname 显示主机名
/etc/rc.d/init.d/network 网络服务启动脚本(service network restart)
/sbin/ifconfig 查看,配置,启用或禁用网络接口(网卡)的 IP 地址,MAC 地址,掩码,广播地址,if 是网络接口 (interface) 的简写
/sbin/ifup ifdown 激活或者终止网络接口
/etc/init.d/network 网络服务启动脚本
Service network start|stop|reload|restart|status|force-reload
/sbin/ifconfig 查看,配置,启用或禁用网络接口(网卡)的工具
ifconfig 是一个用来查看,配置,启用或禁用网络接口的工具,这个工具极为常用的.比如我们可以用这个工具来配置网卡的 IP 地址,MAC 地址,掩码,广播地址等.值得一说的是用 ifconfig 为网卡指定 IP 地址,这只是用来调试网络用的,并不会更改系统关于网卡的配置文件.如果您想把网络接口的 IP 地址固定下来,目前有三个方法:一是通过各个发行和版本专用的工具来修改 IP 地址;二是直接修改网络接口的配置文件;三是修改特定的文件,加入 ifconfig 指令来指定网卡的 IP 地址,比如在 redhat 或 Fedora 中,把 ifconfig 的语名写入 / etc/rc.d/rc.local 文件中;
ifconfig 配置网络接口语法:
ifconfig 网络端口 IP 地址 hw MAC 地址 netmask 掩码地址 broadcast 广播地址 [up/down]
ifconfig 常用用法:
ifconfig : 查看主机激活状态的网络接口情况; 输出结果中:lo 是表示主机的回坏地址,eth0 表示第一块网卡, 其中 HWaddr 表示网卡的物理地址(MAC 地址); inet addr 用来表示网卡的 IP 地址,Bcast 表示广播地址,Mask 表示掩码地址
ifconfig -a : 查看主机所有(包括没有被激活的)网络接口的情况
ifconfig eth0 : 查看特定网络接口的状态
ifconfig eth0 down = ifup eth0 : 如果 eth0 是激活的,就把它终止掉.此命令等同于 ifdown eth0;
ifconfig eth0 up = ifdown eth0 : 激活 eth0 ; 此命令等同于 ifup eth0
ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 : 配置 eth0 的 IP 地址,广播地址和网络掩码;
ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up : 配置 IP 地址,网络掩码,广播地址的同时,激活网卡 eth0
ifconfig eth1 hw ether 00:11:00:00:11:22 : 设置网卡的物理地址(MAC 地址).其中 hw 后面所接的是网络接口类型, ether 表示以太网, 同时也支持 ax25 ,ARCnet,netrom 等,详情请查看 man ifconfig ;
用 ifconfig 来配置虚拟网络接口:
有时我们为了满足不同的需要还需要配置虚拟网络接口,比如我们用不同的 IP 地址来架运行多个 HTTPD 服务器,就要用到虚拟地址;这样就省却了同一个 IP 地址,如果开设两个的 HTTPD 服务器时,要指定端口号.
虚拟网络接口指的是为一个网络接口指定多个 IP 地址,虚拟接口是这样的 eth0:0 , eth0:1,eth0:2 ... .. eth1N.当然您为 eth1 指定多个 IP 地址,也就是 eth1:0,eth1:1,eth1:2 ... ... 以此类推;
ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast 192.168.1.255 up
ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up
注意:指定时,要为每个虚拟网卡指定不同的物理地址;
关联: Name-based Virtual Host Support - Apache 基于域名的虚拟主机设置(1 个 IP,多种服务)
来源: http://www.bubuko.com/infodetail-2472793.html