<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 April 2018 at 11:30, Hans de Groot <span dir="ltr"><<a href="mailto:hansg@dandy.nl" target="_blank">hansg@dandy.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<div class="m_-3827124086505017653gmail-m_3031601068662149481moz-cite-prefix">Hello again :)<br>
<br>
Thank you all for your reply's. Below are the config files of the
3 hosts. <br>
I use tinc in router mode. I do not have a kernel mode config
lines anywhere so tinc must be using the default settings here. <br>
<br>
I added the ipaddressx to subnets on hostc and this works.
Traffic to that ip is now routed via hostc. <br>
But since this ipaddressx address changes often I need to resolve
it automaticaly and change the iptable rules that mark the
packets. I was really hoping to have to do this at one location
(at hosta) and not update the subnets on hostc. (and I also would
like to understand how this works with tinc) <br>
<br>
If I use the old route command I can tell it to route traffic for
a certain ip to a certain gateway. (without tinc)<br>
ie: route add -host 192.168.0.16 gw 10.0.0.1 eth0<br>
I always assumed packets were specifically send to 10.0.0.1 if
packets with destination 192.168.0.16 arrived on this his host.<br>
But Guus says the VIA option has no effect.</div></div></blockquote><div><br></div><div>No, the "via" option doesn't have any effect, because it only has effect at layer 2, e.g. on an Ethernet network. tinc running in router mode is a layer 3 (IP) network, not a layer 2 (Ethernet) network.<br><br></div><div>When you use that option on a layer 2 network such as Ethernet, the "via" option determines which layer 2 host (i.e. which MAC address, after ARP resolution) the packet will go to. In "router mode" tinc there are no MAC addresses, and tinc decides where to send packets based on destination IP address, not the kernel.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div class="m_-3827124086505017653gmail-m_3031601068662149481moz-cite-prefix">So is there a way to
send packets to a specific gateway ip using ip route? <br></div></div></blockquote><div><br></div><div>If you change the tinc mode to "switch", then your tinc VPN will behave just like a physical Ethernet network, and the "via" option will work just like it does on a real network. But note that setting that option comes with a long list of consequences and is quite a radical, breaking change. (Also keep in mind that all nodes on your network need to use the same mode.)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div class="m_-3827124086505017653gmail-m_3031601068662149481moz-cite-prefix">
I do have a subnet 0.0.0.0 at hostb so that is probably why
traffic goes out via hostb when I do not have the specific
subnet/ip at hostc<br></div></div></blockquote><div><br></div><div>Yes, that explains it. If one of your nodes has a 0.0.0.0 subnet then it means tinc will send traffic to that node by default if no other subnets match the destination IP address on the packet. Which is what happened with "ipaddressx".<br><br></div><div>An alternative solution to your problem, besides going one layer down, would be to go one layer up: you could set up a "tunnel within the tunnel", i.e. hosta could establish a tunnel to hostc *on top of* the tinc VPN. Then, if you want certain packets to go through hostc, you can just send them through that tunnel and you're done. I am actually using such a solution for a special purpose on my own tinc network right now. The simplest solution for the tunnel is to use IP/IP, which has minimal overhead and is easy to understand and troubleshoot. I contributed some code to tinc that provides better support for that use case: <a href="https://github.com/gsliepen/tinc/pull/166" target="_blank">https://github.com/gsliepen/<wbr>tinc/pull/166</a><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div class="m_-3827124086505017653gmail-m_3031601068662149481moz-cite-prefix">
Regards<br>
<br>
Hans de Groot <br>
<br>
<br>
configs at hosta<br>
tinc.conf<br>
Name = hosta<br>
Device =/dev/net/tun<br>
Hostnames = No<br>
connectto = hostb<br>
Mode = Router<br>
KeyExpire = 3600<br>
PingInterval = 10<br>
PingTimeout = 15<br>
PrivateKeyFile = /etc/tinc/tincnet/rsa_key.priv<br>
ProcessPriority = high<br>
PMTUDiscovery = yes<br>
<br>
tinc-up<br>
#!/bin/bash<br>
ifconfig $INTERFACE 192.168.230.21 netmask 255.255.255.0<br>
route add -net 192.168.230.0 netmask 255.255.255.0 gw
192.168.230.1<br>
ip route add default via 192.168.230.160 dev tincnet table hostc<span class="m_-3827124086505017653gmail-"><br>
ip rule add from <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a> fwmark 1 table hostc<br>
<br>
<br></span>
hosta<br>
Address = x.x.x.x<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 110<br>
Subnet = <a href="http://192.168.230.21/32" target="_blank">192.168.230.21/32</a><br>
TCPonly = yes<br>
<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<br>
<br>
hostb<br>
Address = x.x.x.x<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 110<br>
Subnet = <a href="http://192.168.230.1/32" target="_blank">192.168.230.1/32</a><br>
Subnet = <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
TCPonly = yes<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<br>
<br>
------------------------------<wbr>-------------------<br>
configs at hostb<br>
tinc.conf<br>
AddressFamily = ipv4<br>
Name = hostb<br>
Device =/dev/net/tun<br>
Hostnames = No<br>
Mode = Router<br>
KeyExpire = 3600<br>
PingInterval = 30<br>
PingTimeout = 60<br>
PrivateKeyFile = /usr/local/etc/tinc/tincnet/rs<wbr>a_key.priv<br>
ProcessPriority = high<br>
PMTUDiscovery = yes<br>
<br>
tinc-up<br>
#!/bin/bash<br>
ifconfig $INTERFACE 192.168.230.1 netmask 255.255.255.0<br>
route add -net 192.168.230.0 netmask 255.255.255.0 gw
192.168.230.1<br>
ip route add default via 192.168.230.160 dev tincnet table hostc<span class="m_-3827124086505017653gmail-"><br>
ip rule add from <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a> fwmark 1 table hostc<br>
<br></span>
hostb<br>
Address = x.x.x.x<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 110<br>
Subnet = <a href="http://192.168.230.1/32" target="_blank">192.168.230.1/32</a><br>
Subnet = <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
TCPonly = No<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<br>
<br>
hostc<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 655<br>
Subnet = <a href="http://192.168.230.160/32" target="_blank">192.168.230.160/32</a><br>
Subnet = <a href="http://10.100.1.241/32" target="_blank">10.100.1.241/32</a><br>
TCPonly = Yes<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<br>
<br>
------------------------------<wbr>-----------------------------<br>
config at hostc<br>
tinc.conf<br>
AddressFamily = ipv4<br>
Name = hostc<br>
ConnectTo = hostb<br>
Interface = tincnet<br>
Hostnames = No<br>
Mode = Router<br>
KeyExpire = 3600<br>
PingInterval = 10<br>
PingTimeout = 10<br>
<br>
tinc-up<br>
#!/bin/bash<br>
ifconfig $INTERFACE 192.168.230.160 netmask 255.255.255.0<br>
<br>
hostb<br>
Address = x.x.x.x<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 110<br>
Subnet = <a href="http://192.168.230.1/32" target="_blank">192.168.230.1/32</a><br>
Subnet = <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
TCPonly = Yes<br>
<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<br>
<br>
<br>
hostc<br>
Address = x.x.x.x<br>
Cipher = blowfish<br>
Compression = 0<br>
Digest = sha1<br>
IndirectData = Yes<br>
Port = 655<br>
Subnet = <a href="http://192.168.230.160/32" target="_blank">192.168.230.160/32</a><br>
Subnet = <a href="http://10.100.2.2/32" target="_blank">10.100.2.2/32</a><br>
Subnet = <a href="http://10.100.1.236/32" target="_blank">10.100.1.236/32</a><br>
TCPonly = Yes<br>
-----BEGIN RSA PUBLIC KEY-----<br>
-----END RSA PUBLIC KEY-----<div><div class="m_-3827124086505017653gmail-h5"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 4/10/2018 11:18 PM, Guus Sliepen wrote:<br>
</div></div></div>
<blockquote type="cite"><div><div class="m_-3827124086505017653gmail-h5">
<pre>On Tue, Apr 10, 2018 at 03:36:08PM +0200, Hans de Groot wrote:
</pre>
<blockquote type="cite">
<pre>hosta <--> hostb <--> hostc
Hosta and hostc are not directly connected via tinc. But both are conncted
via hostb (I called my network tincnet). This works fine I can ssh from
hosta to hostc and vice versa without any problems.
hostc is in a whitelisted iprange at some service provider.
I need hosta to talk to a certain ip (lets call it ipaddressx) via hostc.
I added the iptables mangle rule to mark all traffic to ipaddressx at port
700.
-A OUTPUT -p 6 -m tcp -d ipaddressx/<a href="http://255.255.255.255" target="_blank">255.255.255.255</a> --dport 700 -j MARK
--set-mark 0x1
I added:
ip route add default via iphostc dev tincnet table hostc
ip rule add from <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a> fwmark 1 table hostc
</pre>
</blockquote>
<pre>If you are running tinc in router mode (which is the default), then the
"via iphostc" option does not have any effect. The packets will go to
dev tincnet, but there is nothing in the header of IP packets that
contains the address of the gateway.
Also, if you are using router mode, then you must inform tinc about
which peer to send packets with destination address ipaddressx to. So
you can add "Subnet = ipaddressx/" to hostc's hosts/hostc. But tinc only
routes on address, not on ports.
</pre>
<blockquote type="cite">
<pre>Now when I try this:
traceroute -T -n ipaddressx -p 700
The route goes via the ip of hostb and not via the ip of hostc as I would
have expected.
</pre>
</blockquote>
<pre>There are two possibilities for this: one is that tinc thinks the
packets with destination address ipaddressx should go to hostb (because
of what is in the Subnet statements), the other is that hosta and hostc
cannot directly communicate with each other, and traffic is routed via
hostb, and you have Forwarding = kernel in your tinc.conf. The latter
will force the packets to be sent to the tun interface on hostb, and if
you don't have any rules on hostb to send packets for ipaddressx port
700 to hostc, they will not be forwarded the way you want.
</pre>
<blockquote type="cite">
<pre>A weird thing is when I try the add route with any ip in the tincnet subnet
the route gets added even if that ip is not in use and all traffic still
goes via the ip of hostb.
ie: ip route add default via any_ip_in_the_tincnet_subnet dev tincnet table
hostc
</pre>
</blockquote>
<pre>Again, in router mode, the "via ..." option has no effect at all.
</pre>
<blockquote type="cite">
<pre>Is it tincd at hostb that intercepts the traffic actually meant for hostc
and thinks it's meant for hostb and rewrites stuff automaticaly? Or am I
missing something in the ip route / ip rules part?
</pre>
</blockquote>
<pre>Tinc itself does not rewrite anything.
</pre>
<blockquote type="cite">
<pre>But I really would like to understand how to do this via mangle/fwmark and
ip route / ip rule way.
</pre>
</blockquote>
<pre>It would help if you could show us your tinc.conf from hostb, and all
hosts/* files, so we can check how you configured tinc exactly.
</pre>
<br>
<fieldset class="m_-3827124086505017653gmail-m_3031601068662149481mimeAttachmentHeader"></fieldset>
<br>
</div></div><span class="m_-3827124086505017653gmail-"><pre>______________________________<wbr>_________________
tinc mailing list
<a class="m_-3827124086505017653gmail-m_3031601068662149481moz-txt-link-abbreviated" href="mailto:tinc@tinc-vpn.org" target="_blank">tinc@tinc-vpn.org</a>
<a class="m_-3827124086505017653gmail-m_3031601068662149481moz-txt-link-freetext" href="https://www.tinc-vpn.org/cgi-bin/mailman/listinfo/tinc" target="_blank">https://www.tinc-vpn.org/cgi-b<wbr>in/mailman/listinfo/tinc</a>
</pre>
</span></blockquote>
<p><br>
</p>
</div>
<br>______________________________<wbr>_________________<br>
tinc mailing list<br>
<a href="mailto:tinc@tinc-vpn.org" target="_blank">tinc@tinc-vpn.org</a><br>
<a href="https://www.tinc-vpn.org/cgi-bin/mailman/listinfo/tinc" rel="noreferrer" target="_blank">https://www.tinc-vpn.org/cgi-b<wbr>in/mailman/listinfo/tinc</a><br>
<br></blockquote></div><br></div></div>