-
Notifications
You must be signed in to change notification settings - Fork 10
/
aliaser
executable file
·109 lines (85 loc) · 2.63 KB
/
aliaser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# ----
# Resolve issues with IP aliasing for Amazon EC2 linux virtual machines
# ----
#
if [ $# -lt 1 ]
then
echo "No command specified"
echo "Usage: $0 start, $0 stop, $0 restart, $0 print or $0 test"
echo "Execute $0 -h or $0 help for more detailed usage information"
exit
fi
#echo -n "What is the name of the network alias you would like to bind secondary IPs to? (eth0, eth1, etc): "
#read interface
#printf "\n"
#declare -a ETHINT=($interface)
#case $ETHINT in
function mac-grab {
MAC_ADDR=$(ifconfig eth0 | sed -n 's/.*ether \([a-f0-9:]*\).*/\1/p')
}
function public-grab {
PUBLIC=($(curl -s -f http://169.254.169.254/latest/meta-data/public-ipv4))
}
function private-grab {
PRIVATE=($(curl -s -f http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/local-ipv4s))
}
function primary-private-grab {
PRIMARYPRIV=($(curl -s -f http://169.254.169.254/latest/meta-data/local-ipv4))
}
function private-loop {
for priv in ${PRIVATE[@]:1};
do
echo "Adding IP: $priv"
ip addr add dev eth0 $priv/$SUBNET_CIDR_BLOCK
done
}
function subnet-cidr-block-grab {
SUBNET_CIDR_BLOCK=($(curl -s -f http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/subnet-ipv4-cidr-block | sed -e 's/^.*\///'))
}
case "$1" in
'-h' | '-H' | 'help') printf "\nAliaser v0.01\nUsage: $0 -h\n$0 help\n$0 version\n$0 start\n$0 restart\n$0 stop\n$0 print\n$0 test\n\n"
;;
'version' | '-v' | '-V') printf "aliaser v0.01
-----------------------------------
©2015 Josh Wieder\nhttp://www.joshwieder.net/\njosh.wieder@live.com
-----------------------------------
aliaser comes with ABSOLUTELY NO WARRANTY.
This is free software made available through
the GNU General Public License v2. You are
welcome to redistribute it under certain
conditions - see LICENSE for details.\n\n"
;;
'start') mac-grab
private-grab
subnet-cidr-block-grab
private-loop
;;
'restart') service network restart
mac-grab
private-grab
subnet-cidr-block-grab
private-loop
;;
'stop') service network restart
;;
'print' | '-p' | '-P') mac-grab
primary-private-grab
printf "Primary private IPs: %s\n" "$PRIMARYPRIV"
private-grab
for priv in ${PRIVATE[@]:1};
do
printf "Secondary Private IP: %s\n" "$priv"
done
public-grab
printf "Primary public IP: %s\n\n" "$PUBLIC";
# printf "Interface: %s\n" "$ETHINT";
;;
'test' | 'verify') mac-grab
private-grab
curltest=$(curl -s -f --interface ${PRIVATE[@]:1} ifconfig.me)
printf "Secondary public IP: %s\n" "$curltest"
;;
*) printf "Invalid option - try $0 -h or $0 help for correct usage"
;;
esac