ifconfig eth0:0 192.168.1.10 netmask 255.255.255.0 up删除虚拟网卡:
ifconfig eth0:0 down重启服务器或者网络后,虚拟网卡就失效. 注意:添加的虚拟网卡和原网卡物理地址是一样的。
cat /etc/network/interfaces auto eth0 iface eth0 inet dhcp auto eth0:1 iface eth0:1 inet static address 192.168.11.1 netmask 255.255.255.0 gateway 192.168.11.1 auto eth0:2 iface eth0:2 inet static address 192.168.12.1 netmask 255.255.255.0 gateway 192.168.12.1保存后,重新加载配置文件才会生效,使用如下命令重启网卡:
service networking restart优点: 重启服务器或者网卡配置不会丢失。
#cd /etc/sysconfig/network-scripts/ #cp ifcfg-eth0 ifcfg-eth0:1 #vi ifcfg-eth0:1 DEVICE=eth0 BOOTPROTO=none HWADDR=00:19:D1:24:2A:EC ONBOOT=yes DHCP_HOSTNAME=zhongqg.localdomain IPADDR=192.168.1.55 NETMASK=255.255.252.0 GATEWAY=192.168.0.1 TYPE=Ethernet USERCTL=no IPV6INIT=no PEERDNS=yes修改其中的IPADDR部分为192.168.1.57,然后保存退出并启动该配置文件!
#ifup eth0:1
root@host:~# tunctl The program 'tunctl' is currently not installed. You can install it by typing: apt-get install uml-utilities root@host:~# apt-get install uml-utilities Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: user-mode-linux The following NEW packages will be installed: uml-utilities 0 upgraded, 1 newly installed, 0 to remove and 105 not upgraded. Need to get 61.9 kB of archives. After this operation, 267 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/universe uml-utilities amd64 20070815-1.3ubuntu1 [61.9 kB] Fetched 61.9 kB in 2s (27.7 kB/s) Selecting previously unselected package uml-utilities. (Reading database ... 60223 files and directories currently installed.) Preparing to unpack .../uml-utilities_20070815-1.3ubuntu1_amd64.deb ... Unpacking uml-utilities (20070815-1.3ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... ureadahead will be reprofiled on next reboot Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Setting up uml-utilities (20070815-1.3ubuntu1) ... * Starting User-mode networking switch uml_switch [ OK ] Processing triggers for ureadahead (0.100.0-16) ...
[root@hunterfu]# modinfo tun filename: /lib/modules/2.6.34.7-56.fc13.i686.PAE/kernel/drivers/net/tun.ko alias: char-major-10-200 license: GPL author: (C) 1999-2004 Max Krasnyansky <[email protected]> description: Universal TUN/TAP device driver srcversion: 880DE258930FE60D765B735 depends: vermagic: 2.6.34.7-56.fc13.i686.PAE SMP mod_unload 686
[root@hunterfu ~]# modprobe tun [root@hunterfu ~]# lsmod | grep tun tun 10548 1执行以上命令后,出现如上输出,说明模块加载成功
[root@hunterfu ~]# cat /etc/init.d/config_tap #!/bin/bash # # config_tap Start up the tun/tap virtual nic # # chkconfig: 2345 55 25 USER="root" TAP_NETWORK="192.168.0.1" TAP_DEV_NUM=0 DESC="TAP config" do_start() { if [ ! -x /usr/sbin/tunctl ]; then echo "/usr/sbin/tunctl was NOT found!" exit 1 fi tunctl -t tap$TAP_DEV_NUM -u root ifconfig tap$TAP_DEV_NUM ${TAP_NETWORK} netmask 255.255.255.0 promisc ifconfig tap$TAP_DEV_NUM } do_stop() { ifconfig tap$TAP_DEV_NUM down } do_restart() { do_stop do_start } check_status() { ifconfig tap$TAP_DEV_NUM } case $1 in start) do_start;; stop) do_stop;; restart) do_restart;; status) echo "Status of $DESC: " check_status exit "$?" ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac
[root@hunterfu ~]# chkconfig --add config_tap [root@hunterfu ~]# chkconfig --level 345 config_tap on操作完成后,就可以像其他标准服务一样,通过 service config_tap start 来进行创建和启动操作
root@host# ifconfig -a eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:5922 errors:0 dropped:0 overruns:0 frame:0 TX packets:2002 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:503405 (503.4 KB) TX bytes:322612 (322.6 KB) 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:65536 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) root@host# tunctl Set 'tap0' persistent and owned by uid 0 root@host# ifconfig -a eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:6089 errors:0 dropped:0 overruns:0 frame:0 TX packets:2057 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:514735 (514.7 KB) TX bytes:339978 (339.9 KB) 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:65536 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) tap0 Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@host# tunctl Set 'tap1' persistent and owned by uid 0 root@host# ifconfig -a eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:6323 errors:0 dropped:0 overruns:0 frame:0 TX packets:2116 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:530988 (530.9 KB) TX bytes:347960 (347.9 KB) 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:65536 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) tap0 Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) tap1 Link encap:Ethernet HWaddr 7e:6a:fc:31:18:35 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@host# brctl show bridge name bridge id STP enabled interfaces root@host# ifconfig tap0 0.0.0.0 root@host# ifconfig tap1 0.0.0.0 root@host# ifconfig -a eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:7246 errors:0 dropped:0 overruns:0 frame:0 TX packets:2525 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:595705 (595.7 KB) TX bytes:545518 (545.5 KB) 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:65536 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) tap0 Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) tap1 Link encap:Ethernet HWaddr 7e:6a:fc:31:18:35 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@host# brctl addbr br-zhai root@host# brctl addif br-zhai tap0 root@host# brctl addif br-zhai tap1 root@host# ifconfig -a br-zhai Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed 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:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:7515 errors:0 dropped:0 overruns:0 frame:0 TX packets:2616 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:615539 (615.5 KB) TX bytes:561216 (561.2 KB) 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:65536 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) tap0 Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) tap1 Link encap:Ethernet HWaddr 7e:6a:fc:31:18:35 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@host# brctl show bridge name bridge id STP enabled interfaces br-zhai 8000.7e13f129c0ed no tap0 tap1 root@host# ifconfig br-zhai 192.168.9.1 up root@host# ifconfig br-zhai br-zhai Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed inet addr:192.168.9.1 Bcast:192.168.9.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:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@host# brctl showmacs br-zhai port no mac addr is local? ageing timer 1 7e:13:f1:29:c0:ed yes 0.00 2 7e:6a:fc:31:18:35 yes 0.00 root@host# brctl Usage: brctl [commands] commands: addbr <bridge> add bridge delbr <bridge> delete bridge addif <bridge> <device> add interface to bridge delif <bridge> <device> delete interface from bridge hairpin <bridge> <port> {on|off} turn hairpin on/off setageing <bridge> <time> set ageing time setbridgeprio <bridge> <prio> set bridge priority setfd <bridge> <time> set bridge forward delay sethello <bridge> <time> set hello time setmaxage <bridge> <time> set max message age setpathcost <bridge> <port> <cost> set path cost setportprio <bridge> <port> <prio> set port priority show [ <bridge> ] show a list of bridges showmacs <bridge> show a list of mac addrs showstp <bridge> show bridge stp info stp <bridge> {on|off} turn stp on/off root@host# ifconfig tap0 promisc root@host# ifconfig br-zhai Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed inet addr:192.168.9.1 Bcast:192.168.9.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:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) eth0 Link encap:Ethernet HWaddr fa:16:3e:7b:4e:e1 inet addr:192.168.33.24 Bcast:192.168.47.255 Mask:255.255.240.0 inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1454 Metric:1 RX packets:115463 errors:0 dropped:0 overruns:0 frame:0 TX packets:6834 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:11942923 (11.9 MB) TX bytes:1083602 (1.0 MB) 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:65536 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) tap0 Link encap:Ethernet HWaddr 7e:13:f1:29:c0:ed UP BROADCAST PROMISC 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) tap1 Link encap:Ethernet HWaddr 7e:6a:fc:31:18:35 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:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)