#!/bin/sh # Assuming you want to make a random private /120 prefix in IP and have all of # those addresses assigned to the loopback interface (dev lo), and you're root, # and have https://gitlab.com/ipcalc/ipcalc installed, and aren't in a network # namespace other than global, run: # # If you also want to be able to bind to those IP addresses, run the following command: # sysctl -w net.ipv6.ip_nonlocal_bind = 1 # # # IPv4 is obsolete, so IP in this document means IPv6 # # ~jmjl # Sets NETWORK and PREFIX with the random network # and 120, which is the prefix we have hardcoded in this line. eval "$(ipcalc -r 120 -np)" # Making it such that netpref is the network + prefix so we can give it to ip netpref="${NETWORK}/${PREFIX}" # Adds the address to the loopback interface lo, and sets scope to host as this # IP will only be valid inside this host ip addr add "$netpref" dev lo scope host # Adds a route so that traffic going to the IP range will go to the local # machine ip route add local "$netpref" dev lo