-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing services outside of namespace from within the namespace #262
Comments
This should be doable with Note that from inside the network namespace you will need to use its IP address for the host - e.g. usually |
Great that works! I'll also update the documentation of this feature when I get a spare moment. Just wondering if there's a way to automatically get the ip address for the namespace host? |
The netns IP is available as Lines 156 to 161 in 44e4849
The host IP is available as the Lines 192 to 196 in 44e4849
Also see the USERGUIDE - https://github.com/jamesmcm/vopono/blob/44e484952035dc3e4f73d998814528b8176b2098/USERGUIDE.md#configuration-file FWIW it will only change if you have vopono namespaces running before (or anything else using those addresses - Also maybe for issue #260 it might be good to write both the forwarded port (if it exists) and local IPs to files in the netns dir |
So I am talking about settings in a webapp When I spin up my server I would have vopono in a systemd service. I am basically looking for something like programmatically grabbing the ip address associated with the created namespace and doing something like adding it to the namespace's hosts file (?) so that I could point to e.g. I'm not very adept with this kind of stuff, so forgive me if I'm mis understanding or if this isn't something that's really possible If it's helpful I did so far come up with ns=$(echo $(ip netns list) | awk '{print $1}')
ip=$(sudo ip netns exec "$ns" ip addr show | awk -v ns="$ns" '$0 ~ ns && /inet / {print $2}' | cut -d'/' -f1)
echo "$ip"
echo "$ns" |
That's a good idea, there is already some support to set the hosts file so it shouldn't be too hard to add the fixed entry for the host's IP. |
I've worked at it a bit and I have a solution which is working for me default_hostname="vopono"
# Get the namespace and IP address
ns=$(ip netns list | awk '{print $1}')
ip_address=$(ip a | grep "scope global $ns" | awk '{print $2}' | cut -d '/' -f 1)
# Check if the entry exists in the hosts file
if grep -q "$default_hostname" /etc/hosts; then
# Replace the existing IP address
sed -i "s/^.*$default_hostname.*$/$ip_address $default_hostname/g" /etc/hosts
echo Replaced existing vopono entry
else
# Create a new entry
echo "$ip_address $default_hostname" >> /etc/hosts
echo Created vopono entry
fi I start this in a script once all my vopono stuff has span up and it allows me to access services outside of the namespace through It would be even cooler if this was more tightly integrated into the vopono app itself though |
- Fixes handling of target applications with spaces in the name. This applies for the target application and also postup and predown host scripts. Fixes issue #259 - Add argument handling for postup and predown scripts, so these can be passed arguments now. - Add `vopono.host` entry to the hosts file in the network namespace with the `$VOPONO_HOST_IP` if `--allow-host-access` is used. This allows you to access services on the host at `http://vopono.host:80` etc. from inside the network namespace. Addresses issue #262 - Add `$VOPONO_FORWARDED_PORT` environment variable if `--port-forwarding` or `--custom-port-forwarding` are used for provider port forwarding. Addresses issue #260 - Added details on Plex port forwarding configuration to the USERGUIDE.md
Now on master, with So you can access |
Very cool, thanks |
Let's say I have program A running with vopono inside a namespace, and service B running on my machine as normal, accessible over port 8080.
Program A needs to connect to program B for proper functionality, but I can't work out how I can connect to port 8080 outside of the namespace.
Currently I would have to run both program A and program B in the namespace to be able to access
localhost:8080
from program A.Is there any way to do this without having to have both programs in the namespace?
Thanks
The text was updated successfully, but these errors were encountered: