$ sudo apt install traceroute
$ sudo cat << EOF >> /etc/network/interfaces iface tun1 inet static address 192.168.10.1 netmask 255.255.255.0 pre-up iptunnel add tun1 mode gre local 80.211.xx remote 188.xxx ttl 255 up ifconfig tun1 multicast pointopoint 192.168.10.2 post-down iptunnel del tun1 EOF
$ sudo service networking restart
Received constructive criticism of this method of activating network settings.
$ ifconfig tun1 tun1 Link encap:UNSPEC HWaddr 10-D3-29-B2-00-00-B0-8A-00-00-00-00-00-00-00-00 inet addr:192.168.10.1 PtP:192.168.10.2 Mask:255.255.255.255 inet6 addr: fe80::200:5ffa:50d3:c9c2/64 Scope:Link UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1476 Metric:1 RX packets:379 errors:0 dropped:0 overruns:0 frame:0 TX packets:322 errors:4 dropped:7 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:103387 (103.3 KB) TX bytes:159422 (159.4 KB)
$ ping 192.168.10.2 PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data. 64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=56.0 ms 64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=59.9 ms 64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=56.3 ms 64 bytes from 192.168.10.2: icmp_seq=4 ttl=64 time=56.1 ms --- 192.168.10.2 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 56.091/57.137/59.936/1.618 ms user@vps:~$
$ sudo cat << EOF >> /etc/network/interfaces #static route" up ip ro add 192.168.1.0/24 via 192.168.10.2 up ip ro add 192.168.6.0/24 via 192.168.10.2 EOF
$ sudo service networking restart
$ sudo echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf $ sudo sysctl -p
$ sudo iptables -t nat -A POSTROUTING -j SNAT --to-source 80.211.xx -o eth0
/ip route add comment=linkedin distance=1 dst-address=91.225.248.0/22 gateway=gre-tunnel1 add comment=linkedin distance=1 dst-address=108.174.0.0/20 gateway=gre-tunnel1 add comment=linkedin distance=1 dst-address=185.63.144.0/22 gateway=gre-tunnel1
$ apt install strongswan
$ cat << EOF > /etc/ipsec.conf # ipsec.conf - strongSwan IPsec configuration file config setup charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2, mgr 2" conn %default # keyexchange=ikev2 conn mikrotik # Try connect on daemon start auto=start # Authentication by PSK (see ipsec.secret) authby=secret # Disable compression compress=no # Re-dial setings closeaction=clear dpddelay=30s dpdtimeout=150s dpdaction=restart # ESP Authentication settings (Phase 2) esp=aes128-sha1-modp2048,aes256-sha1-modp2048 # UDP redirects forceencaps=no # IKE Authentication and keyring settings (Phase 1) ike=aes128-sha1-modp2048,aes256-sha1-modp2048 ikelifetime=86400s keyingtries=%forever lifetime=3600s # Internet Key Exchange (IKE) version # Default: Charon - ikev2, Pluto: ikev1 keyexchange=ikev1 # connection type type=transport # Peers left=188.xxx right=80.211.xx # Protocol type. May not work in numeric then need set 'gre' leftprotoport=47 rightprotoport=47 EOF
$ echo "80.211.xx 188.xxx : PSK VeryBigSecret" >> /etc/ipsec.secrets
$ ipsec restart
$ ipsec status Security Associations (1 up, 0 connecting): mikrotik[2]: ESTABLISHED 60 minutes ago, 80.211.xx[80.211.xx]...188.xxx[188.xxx] mikrotik{2}: INSTALLED, TRANSPORT, reqid 1, ESP SPIs: cc075de3_i 07620dfa_o mikrotik{2}: 80.211.xx/32[gre] === 188.xxx/32[gre]
auto tun1 iface tun1 inet static address 192.168.10.1 netmask 255.255.255.0 pre-up iptunnel add tun1 mode gre local 80.211.xx remote 188.xxx ttl 255 up ifconfig tun1 multicast pointopoint 192.168.10.2 mtu 1435 post-down iptunnel del tun1
$ sudo apt install netfilter-persistent
$ cat /etc/iptables/rules.v4 # Generated by iptables-save v1.6.0 on Thu Sep 14 20:36:19 2017 *nat :PREROUTING ACCEPT [17:3042] :INPUT ACCEPT [2:92] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] -A POSTROUTING -o eth0 -j SNAT --to-source 80.211.xx COMMIT # Completed on Thu Sep 14 20:36:19 2017 # Generated by iptables-save v1.6.0 on Thu Sep 14 20:36:19 2017 *filter :INPUT DROP [29:4527] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -p icmp -j ACCEPT # TCP/4022 - ssh ( , port-scan-) # !!! ssh , -A INPUT -p tcp -m tcp --dport 4022 -j ACCEPT -A INPUT -p udp -m udp --dport 500 -j ACCEPT -A INPUT -p gre -j ACCEPT -A INPUT -p esp -j ACCEPT # Forwarding -A FORWARD -j ACCEPT COMMIT # Completed on Thu Sep 14 20:36:19 2017
$ echo "iptables-restore < /etc/iptables/rules.v4" >> /etc/rc.local
$ iptables -L -n -v Chain INPUT (policy DROP 185 packets, 28847 bytes) pkts bytes target prot opt in out source destination 4 344 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 32 896 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 948 66063 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:3022 172 21504 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:500 2864 454K ACCEPT 47 -- * * 0.0.0.0/0 0.0.0.0/0 2864 582K ACCEPT esp -- * * 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 4572 3303K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT 1820 packets, 2974K bytes) pkts bytes target prot opt in out source destination 4797 6544K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Sep 15 19:25:33 vps kernel: [42049.805599] IN=tun1 OUT= MAC= SRC=192.168.10.2 DST=255.255.255.255 LEN=133 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=36233 DPT=5678 LEN=113
Source: https://habr.com/ru/post/337426/
All Articles