host/tatos: add subnets user list
This commit is contained in:
parent
908fc043c5
commit
b6b8e8dc82
4 changed files with 28 additions and 11 deletions
2
nixos/hosts/tatos/services/subnets_user_list.secret.txt
Normal file
2
nixos/hosts/tatos/services/subnets_user_list.secret.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# cache.nixos.org
|
||||||
|
151.101.86.217/32
|
|
@ -1,4 +1,5 @@
|
||||||
{ writeShellScriptBin
|
{ writeShellScriptBin
|
||||||
|
, substituteAll
|
||||||
, symlinkJoin
|
, symlinkJoin
|
||||||
, makeWrapper
|
, makeWrapper
|
||||||
, bind
|
, bind
|
||||||
|
@ -9,7 +10,11 @@
|
||||||
, curl
|
, curl
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
update_ru_routes_unwrapped = writeShellScriptBin "update_ru_routes" (builtins.readFile ./update_ru_routes.sh);
|
update_ru_routes_unwrapped = writeShellScriptBin "update_ru_routes"
|
||||||
|
(builtins.readFile (substituteAll {
|
||||||
|
src = ./update_ru_routes.sh;
|
||||||
|
subnetsUserList = "${./subnets_user_list.secret.txt}";
|
||||||
|
}));
|
||||||
in
|
in
|
||||||
symlinkJoin {
|
symlinkJoin {
|
||||||
name = "update_ru_routes";
|
name = "update_ru_routes";
|
||||||
|
|
|
@ -11,13 +11,15 @@ function ProgressBar {
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
file_raw="russian_subnets_list_raw.txt"
|
file_raw="russian_subnets_list_raw.txt"
|
||||||
# file_user="subnets_user_list.txt"
|
file_user="@subnetsUserList@"
|
||||||
file_for_calc="russian_subnets_list_raw_for_calc.txt"
|
file_for_calc="russian_subnets_list_raw_for_calc.txt"
|
||||||
file_processed="russian_subnets_list_processed.txt"
|
file_processed="russian_subnets_list_processed.txt"
|
||||||
gateway_for_internal_ip=`ip route | awk '/default/ {print $3; exit}'`
|
gateway_for_internal_ip=`ip route | awk '/default/ {print $3; exit}'`
|
||||||
interface=`ip route | awk '/default/ {print $5; exit}'`
|
interface=`ip route | awk '/default/ {print $5; exit}'`
|
||||||
|
|
||||||
# Get addresses RU segment
|
# Get addresses RU segment
|
||||||
|
echo "Add stat.ripe.net to $interface"
|
||||||
|
ip route add 193.0.6.150/32 via $gateway_for_internal_ip dev $interface
|
||||||
echo "Download RU subnets..."
|
echo "Download RU subnets..."
|
||||||
curl --progress-bar "https://stat.ripe.net/data/country-resource-list/data.json?resource=ru" | jq -r ".data.resources.ipv4[]" > $file_raw
|
curl --progress-bar "https://stat.ripe.net/data/country-resource-list/data.json?resource=ru" | jq -r ".data.resources.ipv4[]" > $file_raw
|
||||||
|
|
||||||
|
@ -28,13 +30,13 @@ for line in $(cat $file_for_calc); do
|
||||||
ipcalc --no-decorate -d $line >> $file_processed;
|
ipcalc --no-decorate -d $line >> $file_processed;
|
||||||
done
|
done
|
||||||
|
|
||||||
# if [ -e $file_user ]; then echo "Add user subnets..."; cat $file_user |grep -v "#" >> $file_processed; fi
|
if [ -e $file_user ]; then
|
||||||
|
echo "Add user subnets..."
|
||||||
|
cat $file_user | grep -v "#" >> $file_processed
|
||||||
|
fi
|
||||||
|
|
||||||
# Flush route table
|
echo "Flush route table (restart interface $interface)..."
|
||||||
echo "Flush route table (down interface $interface)..."
|
systemctl restart "network-addresses-${interface}.service"
|
||||||
ifdown $interface > /dev/null 2>&1
|
|
||||||
echo "Up interface $interface..."
|
|
||||||
ifup $interface > /dev/null 2>&1
|
|
||||||
|
|
||||||
# Add route
|
# Add route
|
||||||
routes_count_in_file=`wc -l $file_processed`
|
routes_count_in_file=`wc -l $file_processed`
|
||||||
|
|
|
@ -9,6 +9,8 @@ let
|
||||||
port = tatosData.wireguard.port;
|
port = tatosData.wireguard.port;
|
||||||
|
|
||||||
update_ru_routes = pkgs.callPackage ./update_ru_routes.nix { };
|
update_ru_routes = pkgs.callPackage ./update_ru_routes.nix { };
|
||||||
|
|
||||||
|
dnsport = 53;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
|
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
|
||||||
|
@ -22,7 +24,15 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall = {
|
networking.firewall = {
|
||||||
allowedUDPPorts = [ port ];
|
allowedTCPPorts = [ dnsport ];
|
||||||
|
allowedUDPPorts = [ dnsport port ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.dnsmasq = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
interface = "wg0";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ update_ru_routes ];
|
environment.systemPackages = [ update_ru_routes ];
|
||||||
|
@ -43,14 +53,12 @@ in
|
||||||
interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'`
|
interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'`
|
||||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -o $interface -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -o $interface -j MASQUERADE
|
||||||
${pkgs.iproute}/bin/ip rule add from ${tatosData.addr} table main
|
${pkgs.iproute}/bin/ip rule add from ${tatosData.addr} table main
|
||||||
${pkgs.iproute}/bin/ip route add 193.0.6.150/32 via $gateway dev $interface
|
|
||||||
'';
|
'';
|
||||||
preDown = ''
|
preDown = ''
|
||||||
gateway=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $3; exit}'`
|
gateway=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $3; exit}'`
|
||||||
interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'`
|
interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'`
|
||||||
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -o $interface -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -o $interface -j MASQUERADE
|
||||||
${pkgs.iproute}/bin/ip rule del from ${tatosData.addr} table main
|
${pkgs.iproute}/bin/ip rule del from ${tatosData.addr} table main
|
||||||
${pkgs.iproute}/bin/ip route del 193.0.6.150/32 via $gateway dev $interface
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Path to the private key file.
|
# Path to the private key file.
|
||||||
|
|
Loading…
Reference in a new issue