February 9, 2012

toho71 toho71
Lab Rat
189 posts

[SOLVED]set addresses in linux

 

Hi I have seen a lot of exampels wher the command is

  1.       QString ip = ui->txtAdress->text();
  2.        QString cmd = QString("ifconfig eth0 %1 netmask 255.255.255.0 up").arg(ip);

and not this
  1.      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

4 replies

February 9, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3137 posts

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?

February 9, 2012

toho71 toho71
Lab Rat
189 posts

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

February 13, 2012

toho71 toho71
Lab Rat
189 posts

I used ifconfig and it works great for my purpose

February 13, 2012

fluca1978 fluca1978
Ant Farmer
524 posts

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.

 
  ‹‹ QTreeView: selecting full width of a row without text being truncated      [Solved] Unexpected behavior with atEnd() ››

You must log in to post a reply. Not a member yet? Register here!