一起学习网 一起学习网


一步步教你如何在centos7.6批量增加修改删除虚拟网卡操作介绍

网络编程 一步步教你如何在centos7.6批量增加修改删除虚拟网卡操作介绍 10-08

1 确认内核是否有tun模块

modinfo tun
modprobe tunlsmod | grep tun

2 安装tunctl软件

yum install tunctl -y
vim /etc/yum.repos.d/nux-misc.repo
[nux-misc]name=Nux Miscbaseurl=http://li.nux.ro/download/nux/misc/el7/x86_64/enabled=0gpgcheck=1gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

 

yum --enablerepo=nux-misc install tunctl

软件名称:tunctl-1.5-12.el7.nux.x86_64

3 添加多个ip并绑定到网卡  

cd /etc/sysconfig/network-scriptscp ifcfg-lo ifcfg-lo:1 vim ifcfg-lo:1 

DEVICE=lo:1 
ONBOOT=yes 
BOOTPROTO=static 
IPADDR=新增IP 
NETMASK=子网掩码 
GATEWAY=网关地址 

systemctl restart network

4 批量添加虚拟网卡

tunctl -t tap0 -u root  

tap0 是虚拟网卡名字

ifconfig tap0 172.168.1.1 netmask 255.255.255.0 promisc

172.168.1.1 是ip地址

ip tuntap add tap1 mode tun
tunctl -t tap0 -u root                     ifconfig tap0 172.168.1.1 netmask 255.255.255.0 promiscip tuntap add tap1 mode tapifconfig tap1 10.0.0.1/16ip tuntap add tap2 mode tapifconfig tap2 10.0.0.1/17ip tuntap add tap3 mode tapifconfig tap3 10.0.0.1/18ip tuntap add tap4 mode tapifconfig tap4 10.0.0.1/19ip tuntap add tap5 mode tapifconfig tap5 10.0.0.1/20ip tuntap add tap6 mode tapifconfig tap6 10.0.0.1/21ip tuntap add tap7 mode tapifconfig tap7 10.0.0.1/22ip tuntap add tap8 mode tapifconfig tap8 10.0.0.1/23ip tuntap add tap9 mode tapifconfig tap9 10.0.0.1/24

sh addVirnet.sh 

#!/bin/bash#i=0n=0while [ $n -le 10 ];doi=$(( $i + $n ))n=$(( $n + 1 ))ip tuntap add tap$n mode tapdoneecho $i 

5 批量修改虚拟网卡

ifconfig tap0 192.168.130.17  netmask 255.255.255.0 promisc ifconfig tap1 192.168.130.18  netmask 255.255.255.0 promisc ifconfig tap2 192.168.130.19  netmask 255.255.255.0 promisc ifconfig tap3 192.168.130.20  netmask 255.255.255.0 promisc ifconfig tap4 192.168.130.21  netmask 255.255.255.0 promisc ifconfig tap5 192.168.130.23  netmask 255.255.255.0 promisc ifconfig tap6 192.168.130.24  netmask 255.255.255.0 promiscifconfig tap7 192.168.130.25  netmask 255.255.255.0 promisc ifconfig tap8 192.168.130.28  netmask 255.255.255.0 promisc ifconfig tap9 192.168.130.30  netmask 255.255.255.0 promisc

6 批量删除虚拟网卡

tunctl -d tap0tunctl -d tap1tunctl -d tap2tunctl -d tap3tunctl -d tap4tunctl -d tap5tunctl -d tap6tunctl -d tap7tunctl -d tap8tunctl -d tap9

sh deleteVirnet.sh

#!/bin/bash#i=0n=0while [ $n -le 10 ];doi=$(( $i + $n ))n=$(( $n + 1 ))tunctl -d tap$ndoneecho $i 

其他命令

tunctl
brctl show

brctl addbr br-zhaibrctl addif br-zhai tap0brctl addif br-zhai tap1ifconfig -abrctl showifconfig br-zhai 192.168.9.1 upifconfig br-zhaiifconfig -abrctl showbrctl showmacs br-zhaiifconfig tap0 promiscifconfig

开启自动启动虚拟网卡脚本 

vim /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.130.10"  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   esacn=0while [ $n -le 8 ];don=$(( $n + 1 ))ip tuntap add tap$n mode tapdoneecho $i ifconfig tap0 192.168.1.110  netmask 255.255.255.0 promisc ifconfig tap1 192.168.1.111  netmask 255.255.255.0 promisc ifconfig tap2 192.168.1.112  netmask 255.255.255.0 promisc ifconfig tap3 192.168.1.113  netmask 255.255.255.0 promisc ifconfig tap4 192.168.1.114  netmask 255.255.255.0 promisc ifconfig tap5 192.168.1.115  netmask 255.255.255.0 promisc ifconfig tap6 192.168.1.116  netmask 255.255.255.0 promisc ifconfig tap7 192.168.1.117  netmask 255.255.255.0 promisc ifconfig tap8 192.168.1.118  netmask 255.255.255.0 promisc ifconfig tap9 192.168.1.119  netmask 255.255.255.0 promisc 
chkconfig --add config_tap chkconfig --level 345 config_tap onservice config_tap start 

到此这篇关于centos7.6批量增加修改删除虚拟网卡操作介绍的文章就介绍到这了,更多相关centos7.6增加修改删除网卡内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


编辑:一起学习网

标签:网卡,批量,地址,多个,文章