Re: Programatically change IP Address

Tauno Voipio <tauno.voipio@xxxxxxxxxxxxx> writes:

>ibondre@xxxxxxxxx wrote:
>> How can i programatically change the IP Address, DNS, gateway,
>> Enable/disable DHCP, in Linux Using C or C++.
>> Is there also an API to get this properties?

The dns server is in /etc/resolv.conf. The gateway is set by the route
command or the ip command in more modern situations.
The address of the card is set either by dhcp or by ifconfig.

You can run programs from within your C program (execle)

>The DNS and DHCP settings are in configuration files
>you can modify if you have sufficient access rights.

>To effect the changes you may need to send a signal
>to the corresponding daemon or to restart it.

>The IP addresses and routing information are in
>kernel tables which are accessible with suitable
>ioctl() calls. For details, get a book on network
>programming, e.g.

> W. Richard Stevens, UNIX Network Programming

>Needless to say that the process modifying any network
>settings needs sufficient privileges.

Relevant Pages

  • Re: Non-domain connection problem
    ... Yesterday I even hardcoded the DNS of a local ISP into the TCP/ip properties ... Connect to Internet from Internal Network ... Notice that the default gateway and DNS IP addresses are different, ...
  • Re: Static IP Address HELP !!
    ... Everything should work once I change that gateway address. ... >> to change is to close your DNS Virtual Server on your ... >> using dynDNS to host your DNS externally, ... > Network card on ...
  • Re: Need help with my network
    ... Connection specific DNS suffix....domain_not_set.invalid ... Until recently, this connection worked great. ... can't get the wired one to show up on the network. ... the IP addresses for the computer, the gateway, and DNS. ...
  • Re: Domain controller not found
    ... You said the router is x.x.1.4 and now you say the gateway "knows"? ... This address has nothing to do with your network. ... So the is not longer used on any server or workstation? ... It just seems that the DNS ...
  • Re: Dynamic DNS ??? default gateway ???
    ... I don't think this had anyhting to do with the default gateway or dns. ... it is not on their network and there is no static route for the network ... > two networks together is some of the servers. ...