Gentoo Archives: gentoo-user

From: Graham Murray <graham@×××××××××××.uk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Adding more than one static IP
Date: Mon, 24 Jan 2011 18:01:25
Message-Id: 87vd1e9o87.fsf@newton.gmurray.org.uk
In Reply to: [gentoo-user] Adding more than one static IP by Amar Cosic
1 Amar Cosic <amar.cosic@×××××.com> writes:
2
3 > Hello list
4 >
5 > My mind is just "locked" at the moment and I am trying to figure out
6 > what am I doing wrong here. I have 4 static IP's on server machine
7 > and I have something like this in /etc/conf.d/net :
8 >
9 >
10 >
11 > config_eth0=( "77.xxx.104.14/24" )
12 > routes_eth0=( "default via 77.xxx.104.1" )
13 > config_eth0:1=( "77.xxx.104.100/24" )
14 > routes_eth0:1=( "default via 77.xxx.104.1" )
15 > config_eth0:2=( "77.xxx.104.101/24" )
16 > routes_eth0:2=( "default via 77.xxx.104.1" )
17 > config_eth0:3=( "77.xxx.105.100/24" )
18 > routes_eth0:3=( "default via 77.xxx.105.1" )
19 >
20 >
21 > eth0 works just fine while other ones fail. Could you help me with
22 > this one ?
23
24 Try emerging 'iproute2' (if not already installed) and then adding the
25 following line to /etc/iproute2/rt_tables
26 1 altlan
27
28
29 and then using the following in /etc/conf.d/net
30
31 modules-"iproute2"
32 config_eth0=( "77.xxx.104.14/24" "77.xxx.104.100/32" "77.xxx.104.101/32"
33 "77.xxx.105.100/24" )
34 routes_eth0=( "default via 77.xxx.104.1"
35 "default via 77.xxx.105.1 table altlan"
36 "77.xxx.105.0/24 table altlan" )
37 rules_eth0=( "from 77.xxx.105.100 table altlan" )
38
39 postup() {
40 # This function could be used, for example, to register with a
41 # dynamic DNS service. Another possibility would be to
42 # send/receive mail once the interface is brought up.
43 # Here is an example that allows the use of iproute rules
44 # which have been configured using the rules_eth0 variable.
45 #rules_eth0=" \
46 # 'from 24.80.102.112/32 to 192.168.1.0/24 table localnet priority 100' \
47 # 'from 216.113.223.51/32 to 192.168.1.0/24 table localnet priority 100' \
48 #"
49 eval set -- $\rules_${IFVAR}
50 if [ $# != 0 ]; then
51 einfo "Adding IP policy routing rules"
52 eindent
53 # Ensure that the kernel supports policy routing
54 if ! ip rule list | grep -q "^"; then
55 eerror "You need to enable IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES)"
56 eerror "in your kernel to use ip rules"
57 else
58 for x; do
59 ebegin "${x}"
60 ip rule add ${x} dev "${IFACE}"
61 eend $?
62 done
63 fi
64 eoutdent
65 # Flush the cache
66 ip route flush cache dev "${IFACE}"
67 fi
68 }
69
70 postdown() {
71 # Automatically erase any ip rules created in the example postup above
72 if interface_exists "${IFACE}"; then
73 # Remove any rules for this interface
74 local rule
75 ip rule list | grep " iif ${IFACE}[ ]*" | {
76 while read rule; do
77 rule="${rule#*:}"
78 ip rule del ${rule}
79 done
80 }
81 # Flush the route cache
82 ip route flush cache dev "${IFACE}"
83 fi
84
85 # Return 0 always
86 return 0
87 }