How can I create an environment variable that contains the IP address of an adapter that is set via DHCP?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am using docker and my scripts reference an environment variable that I'm manually setting in user's foo account /etc/environment like:
SERVER_IP=172.16.16.29
I'm using in my docker-compose file (which I'm running under as foo)
environment:
- ServerIP=${SERVER_IP}
I would like to be able to have a variable DHCP_IP that will be populated when adapter enp0s3 has it's IP address set so that I can use DHCP_IP in place of SERVER_IP in the docker-compose above.
I'm not concerned about the IP address changing often as I'm using MAC address filtering in my router to assign the same IP. But I don't want to have to set the IP address manually in a file like I'm doing now.
So how can I put the value of the ip address of enp0s3 into a variable called DHCP_IP, and how can I reference that at the command line or in a file?
Or if you know of an alternative, I'm open to suggestions.
server 18.04 environment-variables
add a comment |
I am using docker and my scripts reference an environment variable that I'm manually setting in user's foo account /etc/environment like:
SERVER_IP=172.16.16.29
I'm using in my docker-compose file (which I'm running under as foo)
environment:
- ServerIP=${SERVER_IP}
I would like to be able to have a variable DHCP_IP that will be populated when adapter enp0s3 has it's IP address set so that I can use DHCP_IP in place of SERVER_IP in the docker-compose above.
I'm not concerned about the IP address changing often as I'm using MAC address filtering in my router to assign the same IP. But I don't want to have to set the IP address manually in a file like I'm doing now.
So how can I put the value of the ip address of enp0s3 into a variable called DHCP_IP, and how can I reference that at the command line or in a file?
Or if you know of an alternative, I'm open to suggestions.
server 18.04 environment-variables
1
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05
add a comment |
I am using docker and my scripts reference an environment variable that I'm manually setting in user's foo account /etc/environment like:
SERVER_IP=172.16.16.29
I'm using in my docker-compose file (which I'm running under as foo)
environment:
- ServerIP=${SERVER_IP}
I would like to be able to have a variable DHCP_IP that will be populated when adapter enp0s3 has it's IP address set so that I can use DHCP_IP in place of SERVER_IP in the docker-compose above.
I'm not concerned about the IP address changing often as I'm using MAC address filtering in my router to assign the same IP. But I don't want to have to set the IP address manually in a file like I'm doing now.
So how can I put the value of the ip address of enp0s3 into a variable called DHCP_IP, and how can I reference that at the command line or in a file?
Or if you know of an alternative, I'm open to suggestions.
server 18.04 environment-variables
I am using docker and my scripts reference an environment variable that I'm manually setting in user's foo account /etc/environment like:
SERVER_IP=172.16.16.29
I'm using in my docker-compose file (which I'm running under as foo)
environment:
- ServerIP=${SERVER_IP}
I would like to be able to have a variable DHCP_IP that will be populated when adapter enp0s3 has it's IP address set so that I can use DHCP_IP in place of SERVER_IP in the docker-compose above.
I'm not concerned about the IP address changing often as I'm using MAC address filtering in my router to assign the same IP. But I don't want to have to set the IP address manually in a file like I'm doing now.
So how can I put the value of the ip address of enp0s3 into a variable called DHCP_IP, and how can I reference that at the command line or in a file?
Or if you know of an alternative, I'm open to suggestions.
server 18.04 environment-variables
server 18.04 environment-variables
asked Mar 25 at 16:29
WhiskerBiscuitWhiskerBiscuit
1386
1386
1
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05
add a comment |
1
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05
1
1
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05
add a comment |
1 Answer
1
active
oldest
votes
Add the following to /etc/bash.bashrc
The adapter in question is: enp0s3
, so change that accordingly
IP="$(ip addr show enp0s3 | awk '$1 == "inet" { print $2 }' | cut -d/ -f1)"
export SERVER_IP=${IP}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128587%2fhow-can-i-create-an-environment-variable-that-contains-the-ip-address-of-an-adap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add the following to /etc/bash.bashrc
The adapter in question is: enp0s3
, so change that accordingly
IP="$(ip addr show enp0s3 | awk '$1 == "inet" { print $2 }' | cut -d/ -f1)"
export SERVER_IP=${IP}
add a comment |
Add the following to /etc/bash.bashrc
The adapter in question is: enp0s3
, so change that accordingly
IP="$(ip addr show enp0s3 | awk '$1 == "inet" { print $2 }' | cut -d/ -f1)"
export SERVER_IP=${IP}
add a comment |
Add the following to /etc/bash.bashrc
The adapter in question is: enp0s3
, so change that accordingly
IP="$(ip addr show enp0s3 | awk '$1 == "inet" { print $2 }' | cut -d/ -f1)"
export SERVER_IP=${IP}
Add the following to /etc/bash.bashrc
The adapter in question is: enp0s3
, so change that accordingly
IP="$(ip addr show enp0s3 | awk '$1 == "inet" { print $2 }' | cut -d/ -f1)"
export SERVER_IP=${IP}
answered Mar 25 at 18:57
WhiskerBiscuitWhiskerBiscuit
1386
1386
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128587%2fhow-can-i-create-an-environment-variable-that-contains-the-ip-address-of-an-adap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
DHCP_IP="$(ip addr show enp0s3 | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
– waltinator
Mar 25 at 17:45
I can get the IP already. How do I put it to a variable?
– WhiskerBiscuit
Mar 25 at 18:05