腾讯云创建辅助网卡实现源进源出

实验环境

操作系统

TencentOS Server 3.1 (TK4)

网络配置

在这里插入图片描述

[root@VM-0-6-centos ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 52:54:00:74:5b:24 brd ff:ff:ff:ff:ff:ff
    inet 172.21.0.6/20 brd 172.21.15.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe74:5b24/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 20:90:6f:8a:29:24 brd ff:ff:ff:ff:ff:ff
    inet 172.21.0.12/20 brd 172.21.15.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::b55f:5ef7:fa45:c620/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

两个网卡

主网卡 172.21.0.6
弹性网卡 172.21.0.12

/etc/iproute2/rt_tables创建一个路由表 wangli

[root@VM-0-6-centos ~]# cat /etc/iproute2/rt_tables
#
# reserved values
#
255	local
254	main
253	default
0	unspec
252	wangli #<----------------here!
#
# local
#
#1	inr.ruhep

设置从辅助网卡172.21.0.12来的流量都要使用wangli这个表

ip rule add from 172.21.0.12 lookup wangli

wangli表添加一个默认路由规则,让流量走eth1辅助网卡

ip route add table wangli default via 172.21.0.1 dev eth1

测试

[root@VM-0-16-centos ~]# ping 172.21.0.6
PING 172.21.0.6 (172.21.0.6) 56(84) bytes of data.
64 bytes from 172.21.0.6: icmp_seq=1 ttl=64 time=0.244 ms
^C
--- 172.21.0.6 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.244/0.244/0.244/0.000 ms
[root@VM-0-16-centos ~]# ping 172.21.0.12
PING 172.21.0.12 (172.21.0.12) 56(84) bytes of data.
64 bytes from 172.21.0.12: icmp_seq=1 ttl=64 time=0.220 ms
^C
--- 172.21.0.12 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.220/0.220/0.220/0.000 ms
[root@VM-0-16-centos ~]#

持久化

/etc/rc.local中写入刚才创建的动作,以便重启后还能生效

[root@VM-0-6-centos ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

/usr/local/qcloud/irq/net_smp_affinity.sh >/tmp/net_affinity.log 2>&1
/usr/local/qcloud/cpuidle/cpuidle_support.sh &> /tmp/cpuidle_support.log
/usr/local/qcloud/rps/set_rps.sh >/tmp/setRps.log 2>&1
/usr/local/qcloud/irq/virtio_blk_smp_affinity.sh > /tmp/virtio_blk_affinity.log 2>&1
/usr/local/qcloud/gpu/nv_gpu_conf.sh >/tmp/nv_gpu_conf.log 2>&1

ip rule add from 172.21.0.12 lookup wangli # <---------------------------------------------here!
ip route add table wangli default via 172.21.0.1 dev eth1 # <---------------------------here!

参考文献

用策略路由解决Linux使用双网卡的问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值