Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED]set addresses in linux
Hi I have seen a lot of exampels wher the command is
@ QString ip = ui->txtAdress->text();
QString cmd = QString("ifconfig eth0 %1 netmask 255.255.255.0 up").arg(ip);
and not this
@ QString cmd = QString("iface eth0 %1 up").arg(ip);
the Iface doesn't seem to work but on debians configuration for static IP they recommend this method
What should I use
That depends heavily on the distribution you are using and the network management method used.
Some distributions use the bare utilities (ifconfig -- already deprecated in some distributions -- or the newer ip), others configure the interface via text files and startup scripts (with or without additional command line utilities), others still use network manager and of course there is always the not so widely used ConnMan.
So you got lots of different ways to do what you want:-) Some require you to run some command(s), others are available via D-Bus interfaces. Of course you may (or may not when using Network Manager or ConnMan) require root access to do this.
Why would you even want to change the IP in the first place?
If the user wants to change the Ip, netmask or gateway on the machine from the application.
And then if the user want to turn on dhcp will also be a command.
My distribution is debian 6.0
I used ifconfig and it works great for my purpose
fluca1978 last edited by
ifconfig is the widely adopted program to manage NICs. It can slightly change in its syntax, but that is the command to go if you need to be as much portable as possible. Other ways rely heavily on the distribution and will nullify the adoption of Qt as cross platform!
By the way, while it is true that each distribution as its own way to set up addresses (text files, nm, scripts,...) each one must obey the ifconfig command.