77 lines
2.5 KiB
Markdown
77 lines
2.5 KiB
Markdown
## Linux
|
|
|
|
See also:
|
|
|
|
- <https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/>
|
|
- <https://www.linode.com/docs/guides/how-to-use-the-linux-ip-command/>
|
|
|
|
The syntax is as follows to add an IPv4/IPv6 address:
|
|
|
|
```sh
|
|
ip addr add {ip_addr/mask} dev {interface}
|
|
```
|
|
|
|
To add a new route, the syntax is:
|
|
|
|
```sh
|
|
ip route add {NETWORK/MASK} via {GATEWAYIP}
|
|
ip route add {NETWORK/MASK} dev {DEVICE}
|
|
|
|
## Add default route using ip ##
|
|
ip route add default {NETWORK/MASK} dev {DEVICE}
|
|
ip route add default {NETWORK/MASK} via {GATEWAYIP}
|
|
```
|
|
|
|
For example, to add a plain route to network `192.168.1.0/24` via gateway `192.168.1.254`:
|
|
|
|
```sh
|
|
ip route add 192.168.1.0/24 via 192.168.1.254
|
|
```
|
|
|
|
## Darwin/BSD
|
|
|
|
See also:
|
|
|
|
- **macOS**:
|
|
- <https://dev.to/dunithd/how-to-set-a-static-ip-address-in-macos-using-command-line-4j1b>
|
|
- **BSD**:
|
|
- <https://man.freebsd.org/cgi/man.cgi?route>
|
|
- <https://man.freebsd.org/cgi/man.cgi?ifconfig>
|
|
- <https://www.cyberciti.biz/faq/how-to-configure-static-ip-address-on-freebsd/>
|
|
|
|
To add an IPv4/IPv6 address in BSD family systems:
|
|
|
|
- **IPv4**: `ifconfig <interface> <address> netmask <netmask>`
|
|
- **IPv6**: `ifconfig <interface> inet6 <address> prefixlen <prefixlength>`
|
|
|
|
To add routes in BSD family systems:
|
|
|
|
- **IPv4**: `route add -net <network_address/prefixlength> <local_address>`
|
|
- **IPv6**: `route add -net -inet6 <network_address/prefixlength> <local_address>`
|
|
|
|
## Windows
|
|
|
|
See also:
|
|
|
|
- <https://techgenix.com/configurestaticipwiththenetshcommand-lineutility/>
|
|
- Netsh Commands:
|
|
- <https://learn.microsoft.com/en-us/windows-server/networking/technologies/netsh/netsh-contexts>
|
|
- <https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc770948(v=ws.10)>
|
|
- <https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731521(v=ws.10)>
|
|
|
|
To add an IPv4/IPv6 address on Windows:
|
|
|
|
- **IPv4**: `netsh interface ipv4 set address <interface> static <address> <netmask>`
|
|
- **IPv4**: `netsh interface ipv6 set address <interface> static <address/prefixlength>`
|
|
|
|
For example, to add a static IPv4 address for "NetLAN1" and specify both the subnet mask and gateway, type:
|
|
|
|
```sh
|
|
netsh interface ipv4 set address "NetLAN1" static <ip_address> <subnet_mask> <gateway>
|
|
```
|
|
|
|
To add routes on Windows:
|
|
|
|
- **IPv4**: `netsh interface ipv4 add route <network_address> <netmask> <interface> <nexthop>`
|
|
- **IPv4**: `netsh interface ipv6 add route <network_address/prefixlength> <interface> <nexthop>`
|