Last active 1726244211

ipv6privateloopback.sh Raw
1#!/bin/sh
2# Assuming you want to make a random private /120 prefix in IP and have all of
3# those addresses assigned to the loopback interface (dev lo), and you're root,
4# and have https://gitlab.com/ipcalc/ipcalc installed, and aren't in a network
5# namespace other than global, run:
6#
7# If you also want to be able to bind to those IP addresses, run the following command:
8# sysctl -w net.ipv6.ip_nonlocal_bind = 1
9#
10#
11# IPv4 is obsolete, so IP in this document means IPv6
12#
13# ~jmjl
14
15# Sets NETWORK and PREFIX with the random network
16# and 120, which is the prefix we have hardcoded in this line.
17eval "$(ipcalc -r 120 -np)"
18
19# Making it such that netpref is the network + prefix so we can give it to ip
20netpref="${NETWORK}/${PREFIX}"
21
22# Adds the address to the loopback interface lo, and sets scope to host as this
23# IP will only be valid inside this host
24ip addr add "$netpref" dev lo scope host
25
26# Adds a route so that traffic going to the IP range will go to the local
27# machine
28ip route add local "$netpref" dev lo
29