Sub topic 9
Restricting logins by IP range and login hours
This chapter assumes you can administer users, profiles, and permission sets, and that you know the session settings from the previous chapter. Here you will limit where and when users can sign in, so a stolen password or a verified session is harder to misuse.
Three controls, three jobs
Salesforce has three network and time controls. They look alike but behave differently.
| Control | Where you set it | What it does |
|---|---|---|
| Login IP ranges | Profile | Blocks logins from addresses outside the range. |
| Trusted IP ranges | Network Access in Setup | Lets logins from these addresses skip identity verification. |
| Login hours | Profile | Blocks logins outside set times, and ends sessions when the window closes. |
The key difference is that login IP ranges and login hours restrict access. Trusted IP ranges relax a challenge. They do not block anyone.
Setting login IP ranges on a profile
Use login IP ranges when a group of users should only work from known networks, such as an office or a VPN.
- In Setup, open Profiles and select the profile.
- Find Login IP Ranges and click New.
- Enter a start and end IP address, then save.
When a profile has at least one range, users on that profile can log in only from addresses inside a listed range. The restriction applies to the browser, the API, and desktop clients.
Setting trusted IP ranges
Trusted IP ranges are set org-wide. In Setup, search for Network Access and add a range. Logins from these addresses are not challenged to verify their identity. Browser logins from outside them are challenged, for example with a code.
Keep the trusted range small. Under MFA enforcement, a broad trusted range can let people skip a step you want everyone to complete. Check the current Salesforce MFA requirements before you rely on a trusted range as a way to bypass verification.
Setting login hours
Login hours suit roles with fixed schedules, such as a support team on shift.
- In Setup, open Profiles and select the profile.
- Find Login Hours and click Edit.
- Set a start and end time for each day. To block a day completely, set both to the same time. For example, 12:00 AM to 12:00 AM.
Times use the org's default time zone, not each user's own. A user who is already signed in when the window closes can keep working in the open session only until it ends, and cannot start a new one.
Common errors
- Locking out administrators. Adding a login IP range to your own profile from an address not on the list ends your access the next time you sign in. Add your current address first.
- Mixing up trusted and login ranges. Trusted ranges never block anyone. Use login IP ranges to block.
- Forgetting the time zone. Login hours follow the org time zone, so a shift in another region may be cut off early.
- Dynamic addresses. Home and mobile connections change addresses. Ranges fit offices and VPNs, not individual remote workers.
Checking the result
After you apply restrictions, review the login history. The query below shows recent attempts, with the source address and status of each. Failures with a restriction message point to a range or hours setting that is too tight.
SELECT UserId, LoginTime, LoginType, SourceIp, Status, Application
FROM LoginHistory
WHERE LoginTime = LAST_N_DAYS:7
ORDER BY LoginTime DESC
LIMIT 200The next chapters cover how to read this data in more detail.
Exercise
A support team works 8 AM to 6 PM Monday to Friday. You want them to sign in only from the office network. Which two profile settings do you use, and why is a trusted IP range the wrong tool?
Show answer
Use Login Hours (8 AM to 6 PM, Monday to Friday, with weekends blocked) and Login IP Ranges (the office addresses) on the team's profile. A trusted IP range only removes the identity challenge for logins from those addresses. It does not block logins from anywhere else.
Exercise
You add a login IP range to the System Administrator profile from your home connection, then sign out. Why might you be unable to sign back in, and how do you prevent this?
Show answer
Your address may not be inside the new range, so the login is denied. Prevent it by adding your current address to the range first, and by keeping a second administrator on a different profile who can change the setting.