CentOS 7.6 batch add, modify and delete virtual network cards operation introduction

CentOS 7.6 batch add, modify and delete virtual network cards operation introduction

1 Check whether the kernel has a tun module

modinfo tun
modprobe tun
lsmod | grep tun 

2 Install tunctl software

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

yum --enablerepo=nux-misc install tunctl

Software name: tunctl-1.5-12.el7.nux.x86_64

3 Add multiple IPs and bind them to the network card

cd /etc/sysconfig/network-scripts
cp ifcfg-lo ifcfg-lo:1 
vim ifcfg-lo:1

DEVICE=lo:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=Add new IP
NETMASK=subnet mask
GATEWAY=Gateway address

systemctl restart network

4 Add virtual network cards in batches

tunctl -t tap0 -u root

tap0 is the name of the virtual network card

ifconfig tap0 172.168.1.1 netmask 255.255.255.0 promisc

172.168.1.1 is the IP address

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

sh addVirnet.sh

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

5 Batch modify virtual network cards

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 promisc
ifconfig 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 Deleting virtual network cards in batches

tunctl -d tap0
tunctl -d tap1
tunctl -d tap2
tunctl -d tap3
tunctl -d tap4
tunctl -d tap5
tunctl -d tap6
tunctl -d tap7
tunctl -d tap8
tunctl -d tap9

sh deleteVirnet.sh

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

Other commands

tunctl
brctl show

brctl addbr br-zhai
brctl addif br-zhai tap0
brctl addif br-zhai tap1
ifconfig -a
brctl show
ifconfig br-zhai 192.168.9.1 up
ifconfig br-zhai
ifconfig -a
brctl show
brctl showmacs br-zhai
ifconfig tap0 promisc
ifconfig

Enable automatic startup of virtual network card script

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 
  esac
n=0
while [ $n -le 8 ];do
n=$(( $n + 1 ))
ip tuntap add tap$n mode tap
done
echo $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 on
service config_tap start

This is the end of this article about the operations of adding, modifying and deleting virtual network cards in batches in centos7.6. For more relevant content about adding, modifying and deleting network cards in centos7.6, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to change the network card name Eth0 in Centos7
  • CentOS7 changes the network card name to eth0 & adds multiple network card configuration in VMWare
  • How to assign multiple IP addresses to a network card on CentOS 7

<<:  Bootstrap 3.0 study notes buttons and drop-down menus

>>:  Practice of dynamically creating dialog according to file name in vue+el-element

Recommend

My CSS framework - base.css (reset browser default style)

Copy code The code is as follows: @charset "...

Centos7 installation of FFmpeg audio/video tool simple document

ffmpeg is a very powerful audio and video process...

Linux kernel device driver virtual file system notes

/******************** * Virtual File System VFS *...

Example of how to mosaic an image using js

This article mainly introduces an example of how ...

Docker image access to local elasticsearch port operation

Using the image service deployed by docker stack,...

CSS text alignment implementation code

When making forms, we often encounter the situati...

How to customize Docker images using Dockerfile

Customizing images using Dockerfile Image customi...

How to automatically start RabbitMq software when centos starts

1. Create a new rabbitmq in the /etc/init.d direc...

Implementation of whack-a-mole game in JavaScript

This article shares the specific code for JavaScr...

Tutorial for installing MySQL 8.0.18 under Windows (Community Edition)

This article briefly introduces how to install My...

Two methods to implement Mysql remote connection configuration

Two methods to implement Mysql remote connection ...

Analysis of the pros and cons of fixed, fluid, and flexible web page layouts

There is a question that has troubled web designe...

How to use custom images in Html to display checkboxes

If you need to use an image to implement the use ...

How to run Hadoop and create images in Docker

Reinventing the wheel, here we use repackaging to...