How Can I Configure Additional & Floating IP Addresses on My Contabo Server?
How can I configure additional & floating IP addresses on my Contabo server?
Additional IPv4 & floating IP addresses will not be added to your system automatically but will have to be configured manually. Without this configuration your additional IP addresses will not work.
The method for configuring your additional IP addresses differ depending on whether they are static or floating IP addresses.
Below you can find how to configure both static and floating IP addresses. Please note after changing the IP's assignments, you still need to configure the IP addresses directly on the server.
How do I configure my additional static IP addresses?
- Login to the Customer Control Panel here.
- From the blue "control panel" on the left hand side of the page select the option "IP Management".
- Here you will see a list of all of your IP addresses as shown below:
- To assign the IP address to a new server simply click the dropdown next to the IP address you need to change and select the server you would like to assign the IP address to:
- Once you're happy with your assignments simply click the blue "Update IP assignments" button and you're done.
How do I configure additional floating IP addresses?
If you have floating IP addresses you will need to setup a script to make sure they are updated on a regular basis. You can find the relevant API documentation here which you will need to use to setup this script.
How do I configure additional IP addresses with keepalived?
- Install keepalived with the following command:
sudo apt install -y keepalived
- Create a keepalived script user with the following command:
sudo useradd -r -s /usr/sbin/nologin keepalived_script
- Create a secure credentials file with the following commands:
sudo touch /etc/contabo_api_creds sudo chmod 600 /etc/contabo_api_creds sudo chown keepalived_script /etc/contabo_api_creds
- Create the contabo-assign-vip executable with the following commands:
touch /usr/local/bin/contabo-assign-vip chmod +x /usr/local/bin/contabo-assign-vip
- Set the following config on instance 1:
global_defs { enable_script_security } vrrp_instance VI_0 { state MASTER interface eth0 virtual_router_id 10 priority 200 unicast_src_ip <instance 1 ip> unicast_peer { <instance 2 ip> } virtual_ipaddress { <vip> } authentication { auth_type PASS auth_pass <password> } notify_master "/usr/local/bin/contabo-assign-vip <vip> (bare-metal|instances) <instance 1 id>" }
- Set the following config on instance 2:
global_defs {
enable_script_security
}
vrrp_instance VI_0 {
state BACKUP
interface eth0
virtual_router_id 10
priority 100
unicast_src_ip <instance 2 ip>
unicast_peer {
<instance 1 ip>
}
virtual_ipaddress {
<vip>
}
authentication {
auth_type PASS
auth_pass <password>
}
notify_master "/usr/local/bin/contabo-assign-vip <vip> (bare-metal|instances) <instance 2 id>" } - Use the following API credentials on both configs:
url = https://auth.contabo.com/auth/realms/contabo/protocol/openid-connect/token
client_id = <client id>
client_secret = <client secret>
username = <username>
password = <password>
[api]
host = https://api.contabo.com - Finally run the following script:
#!/usr/bin/env python3
import configparser, json, sys, urllib.parse, urllib.request, uuid
from urllib.error import HTTPError, URLError
# HTTP request function
def http_req(url, values={}, headers={}):
data = urllib.parse.urlencode(values)
data = data.encode('ascii')
req = urllib.request.Request(url, data, headers)
try:
with urllib.request.urlopen(req, timeout=10) as response:
return response.read().decode('utf-8')
except HTTPError as error:
print(error.status, error.reason)
sys.exit(1)
except URLError as error:
print(error.reason)
sys.exit(1)
except TimeoutError:
print("Error: Request timed out.")
sys.exit(1)
# Read API config file, example:
"""
[auth]
url = https://auth.contabo.com/auth/realms/contabo/protocol/openid-connect/token
client_id = foo
client_secret = bar
username = user
password = pass
[api]
host = https://api.contabo.com
"""
api_config = configparser.ConfigParser()
try:
api_config.read('/etc/contabo_api_creds')
except:
print("Error: Could not read API config from: /etc/contabo_api_creds")
sys.exit(1)
# Read parameters
if len(sys.argv) > 3:
vip = sys.argv[1]
rtype = sys.argv[2]
rid = int(sys.argv[3])
else:
print("Usage: %s <vip> (bare-metal|instances) <id>" % (sys.argv[0]))
sys.exit(2)
# Get authorization token
auth_values = {'client_id': api_config['auth']['client_id'],
'client_secret': api_config['auth']['client_secret'],
'username': api_config['auth']['username'],
'password': api_config['auth']['password'],
'grant_type': 'password'}
auth_resp = http_req(api_config['auth']['url'], values=auth_values)
try:
auth_token = json.loads(auth_resp)
except:
print("Error: Could not parse Auth JSON.")
sys.exit(1)
# API call
api_url = "%s/v1/vips/%s/%s/%i" % (api_config['api']['host'], vip, rtype, rid)
request_id = str(uuid.uuid4())
api_headers = {'Authorization': 'Bearer ' + auth_token['access_token'],
'x-trace-id': sys.argv[0],
'x-request-id': request_id}
api_resp = http_req(api_url, values="", headers=api_headers)
print(request_id)
How can I order additional IP addresses?
You can follow our documentation here to find out how to order additional IP addresses if you're interested.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article