# IP aliasing

## redr0bin

Hello,

Can somebody tell me how to setup ip alias for network interface.

I saw alias_eth? in /etc/conf.d/net, but what is the string style for alias ?

Thx in advance.

----------

## cookie

ifconfig eth0:x ipaddress

where x is a the number of the alis

eg ifconfig eth0:0 192.168.0.1 netmask 255.255.255.0

Hope that helps

----------

## acidreign

He actually asked whats the what the line says...

#alias_eth0="192.168.0.3 192.168.0.4"

Which basically does

ifconfig eth0:0 192.168.0.3 up

ifconfig eth0:0 192.168.0.4 up

----------

## Pog

after looking to forums and seeing nothing except those thread

I post my conf I does after looking ath net.eth script  :Wink: 

```

iface_eth1="192.168.20.18 broadcast 192.168.20.23 netmask 255.255.255.248"

# Aliasing

alias_eth1="192.168.20.19 192.168.20.20"

broadcast_eth1="192.168.20.23 192.168.20.23"

netmask_eth1="255.255.255.248 255.255.255.248"

```

that gave me the following: 

```

eth1      Link encap:Ethernet  HWaddr 00:0D:60:D5:F1:F7

          inet addr:192.168.20.18  Bcast:192.168.20.23  Mask:255.255.255.248

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:12391 errors:0 dropped:0 overruns:0 frame:0

          TX packets:9567 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:17707497 (16.8 Mb)  TX bytes:774962 (756.7 Kb)

          Interrupt:25

eth1:1    Link encap:Ethernet  HWaddr 00:0D:60:D5:F1:F7

          inet addr:192.168.20.19  Bcast:192.168.20.23  Mask:255.255.255.248

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

          Interrupt:25

eth1:2    Link encap:Ethernet  HWaddr 00:0D:60:D5:F1:F7

          inet addr:192.168.20.20  Bcast:192.168.20.23  Mask:255.255.255.248

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

          Interrupt:25

```

----------

## Fenixoid

how to add routes alias?

e.g. 

```
config_eth0=( "192.168.1.77 netmask 255.255.255.0 brd 192.168.1.255" )

routes_eth0=( "default gw 192.168.1.253" )

#real ip

alias_eth0=( "a.b.c.d netmask 255.255.255.252 brd a.b.c.d1" )

alias_routes_eth0=( "default gw xxx.xxx.xxx.xxx" )
```

alias_routes_eth0 or what?

----------

## UberLord

```
config_eth0=(

  "192.168.1.77 netmask 255.255.255.0 brd 192.168.1.255"

  "a.b.c.d netmask 255.255.255.252 brd a.b.c.d1"

)

routes_eth0=(

   "default gw xxx.xxx.xxx.xxx"

   "default gw 192.168.1.253"

)
```

Obviously you can only have one route per interface, but that's how it's done.

----------

## Fenixoid

Thanks  :Smile: 

----------

## tnt

On my router I have 2 IP addresses associated with one iface eth0 x.x.244.8 and x.x.244.9:

```
route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

x.x.244.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.128.0.0      0.0.0.0         255.255.255.0   U     0      0        0 eth2

10.2.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth1

10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth1

10.1.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         x.x.244.245  0.0.0.0         UG    0      0        0 eth0

ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:XX:XX:XX:XX:XX

          inet addr:x.x.244.8  Bcast:x.x.244.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:641224 errors:0 dropped:0 overruns:0 frame:0

          TX packets:41067 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:798043577 (761.0 Mb)  TX bytes:19941076 (19.0 Mb)

          Interrupt:217 Memory:db000000-0

ifconfig eth0:1

eth0:1    Link encap:Ethernet  HWaddr 00:XX:XX:XX:XX:XX

          inet addr:x.x.244.9  Bcast:x.x.244.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:217 Memory:db000000-0

```

Is there some way to make ALL packets routed from inner NAT-ed networks (10.x.x.x) go out with SRC=x.x.244.8 in their headers?

----------

## tnt

anyone?   :Rolling Eyes: 

----------

## mekong

How about SNAT?

```
iptables -j SNAT -h
```

----------

## tnt

thank you for the answer.

will that mess my firewall up because I have some ruls that depend on 'state' of the connection?

----------

