You are not logged in.

#1 2017-10-21 13:40:30

7thSon
Member
Registered: 2017-05-07
Posts: 186

[SOLVED] Creating a static route to a URL

I have had a static route set up previously on Windows where the route has directed traffic from the desktop PC via my NAS when visiting specific web page.
What I want to achieve is: Desktop PC ----> NAS -----> WWW (Site needs to perceive visitor as the NAS VPN IP, not PC non-VPN IP).

I used to do it on windows by adding this route in a cmd:

route -p ADD web.page.ip.number MASK 255.255.255.0 192.168.1.100

I would like to do the same in Arch, and I tried this:

ip route add web.page.ip.number/24 via 192.168.1.100 dev enp5s0

Is that equivalent of what the windows command was doing? This command gives me an error "Invalid prefix for given prefix length.".

The NAS is set up with iptables as per this script:

#!/bin/bash

#
# Change this variable to match your private network.
#
PRIVATE_NETWORK="192.168.1.0/24"

#
# Change this variable to match your public interface - either eth0 or eth1
#
PUBLIC_INTERFACE="tun0"

#
# Set PATH to find iptables
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin

#
# Module list where KERNEL_MODULES_NAT are defined.
#
IPTABLES_MODULE_LIST="/usr/syno/etc/iptables_modules_list"
source "${IPTABLES_MODULE_LIST}"

#
# Tool to load kernel modules (modprobe does not work for me)
#
BIN_SYNOMODULETOOL="/usr/syno/bin/synomoduletool"

#
# My service name - let's make sure we don't conflict with synology
#
SERVICE="skynet_nat"

#
# iptable binary
#
IPTABLES="iptables"

start() {
    #
    # Log execution time
    #
    date

    #
    # Make sure packet forwarding is enabled.
    # 'sysctl -w net.ipv4.ip_forward=1' does not work for me
    #
    echo 1 > /proc/sys/net/ipv4/ip_forward

    #
    # Count the number of modules so that we can verify if the module
    # insertion was successful. We replace whitespaces with newlines
    # and count lines.
    #
    MODULE_COUNT=$(
        echo "${KERNEL_MODULES_NAT}" |
            gawk '{ print gensub(/\s+/, "\n", "g") }' |
            wc -l
    )

    #
    # Load the kernel modules necessary for NAT
    #
    "${BIN_SYNOMODULETOOL}" --insmod "${SERVICE}" ${KERNEL_MODULES_NAT}
    RV=$?

    #
    # $BIN_SYNOMODULETOOL returns the number of loaded modules as return value
    #
    [[ "${RV}" == "${MODULE_COUNT}" ]] || {
            echo >&2 "Error: Modules were not loaded. The following command failed:"
            echo >&2 "${BIN_SYNOMODULETOOL}" --insmod "${SERVICE}" ${KERNEL_MODULES_NAT}
            exit 1
        }

    #
    # Turn on NAT.
    #
    "${IPTABLES}" -t nat -A POSTROUTING -s "${PRIVATE_NETWORK}" -j MASQUERADE -o "${PUBLIC_INTERFACE}"
    RV=$?
    [[ "${RV}" == "0" ]] || {
            echo >&2 "Error: MASQUERADE rules could not be added. The following command failed:"
            echo >&2 "${IPTABLES}" -t nat -A POSTROUTING -s "${PRIVATE_NETWORK}" -j MASQUERADE -o "${PUBLIC_INTERFACE}"
            exit 1
        }

    #
    # Log current nat table
    #
    iptables -L -v -t nat
}

case "$1" in
        start)
                start
                exit
                ;;
        *)
                #
                # Help message.
                #
                echo "Usage: $0 start"
                exit 1
                ;;
esac

Any help much appreciated

Last edited by 7thSon (2017-10-21 23:25:30)

Offline

#2 2017-10-21 15:42:44

nesk
Member
Registered: 2011-03-31
Posts: 181

Re: [SOLVED] Creating a static route to a URL

Are you sure the mask you specified (/24) is correct? Can you try it without the mask and see if it works?

Offline

#3 2017-10-21 16:09:23

djgera
Developer
From: Buenos Aires - Argentina
Registered: 2008-12-24
Posts: 723
Website

Re: [SOLVED] Creating a static route to a URL

if you want route an specified ip address remove /24 or use redundant /32, but if you still want a /24 range, then remove correcponding bits from the ip address (ie 10.9.7.123/24 wrong, should be 10.9.7.0/24)

Offline

#4 2017-10-21 23:25:10

7thSon
Member
Registered: 2017-05-07
Posts: 186

Re: [SOLVED] Creating a static route to a URL

Thanks for the suggestion, removing the mask worked! smile
I didn't see that as an option since that was part of the Windows command.

Cheers!

As a bonus question - how do I make the static route persisten over reboots?

Last edited by 7thSon (2017-10-21 23:27:46)

Offline

#5 2017-10-22 07:30:41

nesk
Member
Registered: 2011-03-31
Posts: 181

Re: [SOLVED] Creating a static route to a URL

7thSon wrote:

As a bonus question - how do I make the static route persisten over reboots?

Depends on network management program that you use (Netctl, NetworkManager etc).

Offline

#6 2017-10-22 11:15:15

7thSon
Member
Registered: 2017-05-07
Posts: 186

Re: [SOLVED] Creating a static route to a URL

nesk wrote:
7thSon wrote:

As a bonus question - how do I make the static route persisten over reboots?

Depends on network management program that you use (Netctl, NetworkManager etc).

I'm not using networkmanager, so I guess netctl. I didn't install anything specific for networking.

Last edited by 7thSon (2017-10-22 11:15:25)

Offline

#7 2017-10-22 11:51:43

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [SOLVED] Creating a static route to a URL

7thSon wrote:

I'm not using networkmanager, so I guess netctl. I didn't install anything specific for networking.

You guess? You should know what you used to set up your network. Did you use dhcpcd directly, put "ip" commands in your autostart, or did you configure systemd-networkd or netctl?

netctl profiles have a "Routes" array where you can add your custom routes, systemd-networkd has [Route] sections in the configuration, while dhcpcd provides hooks

Last edited by progandy (2017-10-22 11:57:48)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#8 2017-10-22 14:06:58

7thSon
Member
Registered: 2017-05-07
Posts: 186

Re: [SOLVED] Creating a static route to a URL

progandy wrote:
7thSon wrote:

I'm not using networkmanager, so I guess netctl. I didn't install anything specific for networking.

You guess? You should know what you used to set up your network. Did you use dhcpcd directly, put "ip" commands in your autostart, or did you configure systemd-networkd or netctl?

netctl profiles have a "Routes" array where you can add your custom routes, systemd-networkd has [Route] sections in the configuration, while dhcpcd provides hooks

Sorry for my vague answer, networking is really something I'm not very good at. To answer your question I used dhcpcd initally, then as far as I can recall I've only used "ip" commands to try different things, I've done minimal configuring of my network overall.
I dont recognize the netctl commands nor systemd-networkd, so I would have to say I didn't use those after all.
Again, sorry for the confusion, its hard for me to remember what I've done and haven't since I'm not too well versed in this field.

Offline

#9 2017-10-22 14:19:06

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [SOLVED] Creating a static route to a URL

No problem, I didn't mean to sound harsh. You probably still use dhcpcd, then. Dhcpcd should then appear as an enabled systemd service.

systemctl list-unit-files --state=enabled

Here is some information for dhcpcd and static routes:
https://wiki.archlinux.org/index.php/Dh … ute.28s.29


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#10 2017-10-24 13:18:50

7thSon
Member
Registered: 2017-05-07
Posts: 186

Re: [SOLVED] Creating a static route to a URL

progandy wrote:

No problem, I didn't mean to sound harsh. You probably still use dhcpcd, then. Dhcpcd should then appear as an enabled systemd service.

systemctl list-unit-files --state=enabled

Here is some information for dhcpcd and static routes:
https://wiki.archlinux.org/index.php/Dh … ute.28s.29

Thanks, I got it working by setting a dhcpcd hook as described in your link smile

Offline

#11 2017-10-25 07:07:10

positronik
Member
Registered: 2016-02-08
Posts: 94

Re: [SOLVED] Creating a static route to a URL

Hi, wouldn't be better to remove the word 'URL' in the title since this is not actually what you're doing here?
From my understanding this is just creating a static ipv4 route and has nothing to do with URL's.

Offline

Board footer

Powered by FluxBB