網(wǎng)站首頁 編程語言 正文
1 確認(rèn)內(nèi)核是否有tun模塊
modinfo tun
modprobe tun lsmod | grep tun
2 安裝tunctl軟件
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
軟件名稱:tunctl-1.5-12.el7.nux.x86_64
3 添加多個(gè)ip并綁定到網(wǎng)卡 ?
cd /etc/sysconfig/network-scripts cp ifcfg-lo ifcfg-lo:1 vim ifcfg-lo:1
DEVICE=lo:1?
ONBOOT=yes?
BOOTPROTO=static?
IPADDR=新增IP?
NETMASK=子網(wǎng)掩碼?
GATEWAY=網(wǎng)關(guān)地址?
systemctl restart network
4 批量添加虛擬網(wǎng)卡
tunctl -t tap0 -u root
tap0 是虛擬網(wǎng)卡名字
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 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 批量修改虛擬網(wǎng)卡
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 批量刪除虛擬網(wǎng)卡
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
其他命令
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
開啟自動(dòng)啟動(dòng)虛擬網(wǎng)卡腳本?
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
原文鏈接:https://blog.csdn.net/qq_31086997/article/details/121884793
相關(guān)推薦
- 2022-08-25 C++示例講解vector容器_C 語言
- 2022-07-10 jQuery表格添加數(shù)據(jù)并Ajax提交數(shù)據(jù)
- 2022-07-09 JQuery中this的指向詳解_jquery
- 2022-05-17 IDEA自帶maven報(bào)錯(cuò)maven-default-http-blocker (http://0.
- 2022-05-24 Flutter滾動(dòng)組件之SingleChildScrollView使用詳解_Android
- 2022-02-11 SQL中ISNULL函數(shù)使用介紹_數(shù)據(jù)庫其它
- 2022-04-22 arm-linux使用qt開發(fā)并加入openssl
- 2022-03-08 C語言設(shè)計(jì)前中后隊(duì)列實(shí)例代碼_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支