简体   繁体   中英

Changing IP address using .net core on Linux

Is there a way to use .net core code to change networking configuration (IP address, mask, default gateway, DNS, DHCP) On a Linux operating system? (I am using Ubuntu 18.4.2 LTS )

I can use for some extent the following libraries:

System.Net
System.Net.NetworkInformation

https://docs.microsoft.com/en-us/dotnet/api/system.net?view=netcore-2.2

using them I can get the networking information (the IP and the gateway are retrieved properly, the DNS information is always "127.0.0.53", and the DHCP information not supported on Linux), but I can't find in the .net documentation how to set/change the networking configuration like IP address, gateway, etc.

As far I know, there is no built-in way to do this with .NET Core framework. And IMHO there will never be.

But of course, you can do it with invoking system commands. You can use ProcessStartInfo and then call these (and any other) commands.

ifconfig eth0 192.168.66.6 netmask 255.255.255.0 up
route add default gw 192.168.1.1
...

Of course, your process must run as superuser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM