GithubHelp home page GithubHelp logo

Comments (1)

samueljaydan avatar samueljaydan commented on July 22, 2024

This is my iptables ruleset. Is this about the code or iptables ruleset?
I cannot see the change of the packet mark. Can you help me to fix it.

#!/bin/bash

echo 1 >| /proc/sys/net/ipv4/ip_forward
#echo 2 >| /proc/sys/net/ipv4/conf/all/rp_filter

iptables -F
iptables -t mangle -F
iptables -t mangle -X
iptables -t nat -F
iptables -t nat -X
# MARK 1 for WAN1
iptables -t mangle -N CONNMARK1
iptables -t mangle -A CONNMARK1 -j MARK --set-mark 1
iptables -t mangle -A CONNMARK1 -j CONNMARK --save-mark
# MARK 2 for WAN2
iptables -t mangle -N CONNMARK2
iptables -t mangle -A CONNMARK2 -j MARK --set-mark 2
iptables -t mangle -A CONNMARK2 -j CONNMARK --save-mark
#
iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
# TCP LOADBALANCE
iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m conntrack --ctstate NEW -m statistic --mode random --probability 0.5 -j CONNMARK1
iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m conntrack --ctstate NEW -m mark --mark 0x0 -j CONNMARK2
# NON TCP LOADBALANCE
iptables -t mangle -A PREROUTING ! -p tcp -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m statistic --mode random --probability 0.5 -j CONNMARK1 
iptables -t mangle -A PREROUTING ! -p tcp -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m mark --mark 0x0 -j CONNMARK2 
# NFQUEUE
iptables -A FORWARD -i enp3s0 -o enp2s0 -j NFQUEUE --queue-balance 0:3
iptables -A FORWARD -i enp2s0 -o enp3s0 -j NFQUEUE --queue-balance 0:3 
iptables -A FORWARD -i enp3s0 -o enp4s0 -j NFQUEUE --queue-balance 0:3 
iptables -A FORWARD -i enp4s0 -o enp3s0 -j NFQUEUE --queue-balance 0:3 
# NAT
iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE 
iptables -t nat -A POSTROUTING -o enp4s0 -j MASQUERADE 
#
if ! cat /etc/iproute2/rt_tables | grep -q '^251'
then
    echo '251     WAN1' >> /etc/iproute2/rt_tables
fi
if ! cat /etc/iproute2/rt_tables | grep -q '^252'
then
    echo '252     WAN2' >> /etc/iproute2/rt_tables
fi
# ROUTING TABLE FOR WAN1
ip route flush table WAN1 2>/dev/null
ip route add table WAN1 default via 10.10.12.1 dev enp2s0
# ROUTING TABLE FOR WAN2
ip route flush table WAN2 2>/dev/null
ip route add table WAN2 default via 192.168.1.1 dev enp4s0
# FwMark Tables
ip rule del from all fwmark 0x1 lookup WAN1 2>/dev/null
ip rule del from all fwmark 0x2 lookup WAN2 2>/dev/null
ip rule del from all fwmark 0x2 2>/dev/null
ip rule del from all fwmark 0x1 2>/dev/null
ip rule add fwmark 1 table WAN1
ip rule add fwmark 2 table WAN2
#
ip route flush cache
#

from go-netfilter-queue.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.