LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Mac Permanent IP

We have a team of developers using MacBook Pros for development, and they have to travel from one office to another. When the laptop joins the WIFI network at a different location, a brand new IP address is allocated. This should be an issue for most docker containers running on the laptop except Kafka as it has to advertise to DOCKER_HOST_IP.

We can use ifconfig to find the real IP address and export it with the following command.

export DOCKER_HOST_IP=10.200.10.1

After that, we can stop and restart the docker-compose for eventuate local environment. It is doable but not very convenient. To allow developers to start the eventuate docker-compose only once and use it until the laptop is rebooted, we need to find a way to set up a fixed IP address for the MacBook Pro.

On Mac, you can use the following command to create an alias network interface and assign a fixed IP to it.

sudo ifconfig lo0 alias 10.200.10.1/24  # an unused IP address

Once this is done, you can use the above export command to bind this IP to DOCKER_HOST_IP and pass it to the Kafka docker container. It works until you restart your laptop. How can we make it into the startup script so that we don’t need to remember that every time you restart your computer?

We can put the export command into .profile file under home directory. But the command to create an alias is executed with sudo.

For this special case, we need to utilize launchd to kick off a short script with the ifconfig command you used above.

Here is a sample .plist file, saved as com.user.lo0-loopback.plist (can be saved anywhere as it will be copied to the appropriate directory later).

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd > 
<plist version="1.0"> 
<dict> 
  <key>Label</key> 
  <string>com.user.lo0-loopback</string> 
  <key>ProgramArguments</key> 
  <array> 
    <string>/sbin/ifconfig</string> 
    <string>lo0</string> 
    <string>alias</string> 
    <string>10.200.10.1</string> 
  </array> 
  <key>RunAtLoad</key> <true/> 
  <key>Nice</key> 
  <integer>10</integer> 
  <key>KeepAlive</key> 
  <false/> 
  <key>AbandonProcessGroup</key> 
  <true/> 
  <key>StandardErrorPath</key> 
  <string>/var/log/loopback-alias.log</string> 
  <key>StandardOutPath</key> 
  <string>/var/log/loopback-alias.log</string> 
</dict> 
</plist>

Next, move it to the /Library/LaunchDaemons/ directory so it’s kicked off at boot (will be run as root) and set the correct permissions.

$ sudo cp com.user.lo0-loopback.plist /Library/LaunchDaemons/ 
$ sudo chmod 0644 /Library/LaunchDaemons/com.user.lo0-loopback.plist 
$ sudo chown root:wheel /Library/LaunchDaemons/com.user.lo0-loopback.plist

Then load it with launchctl

$ launchctl load /Library/LaunchDaemons/com.user.lo0-loopback.plist

Reboot and your lo0 loopback should have an alias IP assigned to it that will be persistent across reboots.

With above steps done, you can put the export command into the .profile. Here is the .profile file for my MacBook Pro.

#export JAVA_HOME=`/usr/libexec/java_home -v 9.0.4`
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_101`
export PATH="$HOME/.cargo/bin:$PATH"
export DOCKER_HOST_IP=10.200.10.1

Now you can reboot your laptop and double check if the network interface alias is still there with the following command

ifconfig

The result should be something like this.

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 10.200.10.1 netmask 0xffffff00 
    nd6 options=201<PERFORMNUD,DAD>

After confirming this alias is working all the time, you can refer to light-eventuate-4j getting started to start the docker-compose for eventuate local development environment.

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Mac Permanent IP” was last updated: July 5, 2021: fixes #275 checked and corrected grammar/spelling for majority of pages (#276) (b3bbb7b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute