Q
Q
q2zoff2019-07-07 23:30:18
linux
q2zoff, 2019-07-07 23:30:18

How to set the primary IP address on a network interface?

Hello!
There are three IP addresses configured for one network interface:

spoiler
auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 192.168.1.42
    netmask 255.255.255.0
    gateway 192.168.1.1

auto eth0:0
iface eth0:0 inet static
    address 192.168.1.43
    netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
    address 192.168.1.44
    netmask 255.255.255.0

Actually, how to set the main IP address that the system will choose by default for outgoing connections?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2019-07-08
@ky0

You obviously have the main one - the 42nd. If you want to send via another - add a route or change the address to eth0.

L
Lev Zabudkin, 2019-12-14
@zabudkin

Your output will be 192.168.1.42
If you want another, then the rules of iptables.
As an example, let's say you have ip 192.168.1.200 and you need to release it with ip 192.168.1.44:
iptables -A FORWARD -s 192.168.1.200 -j ACCEPT
iptables -A POSTROUTING -s 192.168.1.200 -o eth0 -j SNAT --to -source 192.168.1.44
this is specific in your case, just specifying any ip address will not work, only the one that is in the system, but there are those in the system that you have indicated above (well, to which the reverse route will be built, the left ip cannot be specified).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question