Julian Marcos revised this gist . Go to revision
1 file changed, 23 insertions, 1 deletion
ipv6privateloopback.sh
@@ -1,6 +1,28 @@ | |||
1 | 1 | #!/bin/sh | |
2 | - | # Asuming you want to make a random private /120 prefix in IPv6 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, run: | |
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. | |
3 | 17 | eval "$(ipcalc -r 120 -np)" | |
18 | + | ||
19 | + | # Making it such that netpref is the network + prefix so we can give it to ip | |
4 | 20 | netpref="${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 | |
5 | 24 | ip 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 | |
6 | 28 | ip route add local "$netpref" dev lo |
Julian Marcos revised this gist . Go to revision
1 file changed, 6 insertions
ipv6privateloopback.sh(file created)
@@ -0,0 +1,6 @@ | |||
1 | + | #!/bin/sh | |
2 | + | # Asuming you want to make a random private /120 prefix in IPv6 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, run: | |
3 | + | eval "$(ipcalc -r 120 -np)" | |
4 | + | netpref="${NETWORK}/${PREFIX}" | |
5 | + | ip addr add "$netpref" dev lo scope host | |
6 | + | ip route add local "$netpref" dev lo |